July 2008
Beginner
356 pages
6h 8m
English
Now that you know the basic primitive data types in JavaScript, it's time to move to a more interesting data structure—the array.
To declare a variable that contains an empty array, you use square brackets with nothing between them:
>>> var a = []; >>> typeof a;
"object"
typeof returns "object", but don't worry about this for the time being, we'll get to that when we take a closer look at objects.
To define an array that has three elements, you do this:
>>> var a = [1,2,3];
When you simply type the name of the array in the Firebug console, it prints the contents of the array:
>>> a
[1, 2, 3]
So what is an array exactly? It's simply a list of values. Instead of using one variable to store one value, you can use one array variable to store ...
Read now
Unlock full access