Skip to content

Commit 0b691b4

Browse files
author
Stefan Baumgartner
committed
worked in comments by ajpiano
1 parent e9dee6c commit 0b691b4

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

content/javascript-101/arrays.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,32 @@
22
chapter : js101
33
section: 6
44
title: Arrays
5-
attribution: jQuery Fundamentals, Stefan Baumgartner (@ddprrt)
5+
attribution:
6+
- jQuery Fundamentals
7+
- Stefan Baumgartner
8+
github: ddprrt
69
---
7-
Arrays are zero-indexed lists of values. They are a handy way to store a set of
10+
Arrays are zero-indexed, ordered lists of values. They are a handy way to store a set of
811
related items of the same type (such as strings), though in reality, an array
9-
can include multiple types of items, including other arrays. Arrays in Javascript
10-
work bascially like in most other programming or scripting languages, although there
11-
are some subtle differences.
12+
can include multiple types of items, including other arrays.
1213

1314
To create an array you can either use the object constructor or the literal declaration,
14-
by assign your variable a list of values right after the declaration.
15+
by assigning your variable a list of values right after the declaration.
1516

1617
<javascript caption="A simple array">
1718
var myArray1 = new Array( 'hello', 'world' ); // with constructor
18-
var myArray2 = [ 'hello', 'world' ]; // literal declaration, the prefered way
19+
var myArray2 = [ 'hello', 'world' ]; // literal declaration, the preferred way
1920
</javascript>
2021

22+
The literal declaration is preferred, see the
23+
[Google Coding Guidelines](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Array_and_Object_literals)
24+
for more information.
25+
2126
If you don't know your values yet, it is also possible to declare an empty Array, and
2227
add elements either through functions or through accessing by index:
2328

2429
<javascript caption="Creating empty arrays and adding values">
25-
var myArray = []; // var myArray = new Array(); would also work
30+
var myArray = [];
2631

2732
myArray.push('hello'); // adds 'hello' on index 0
2833
myArray.push('world'); // adds 'world' on index 1

0 commit comments

Comments
 (0)