To create an array in JavaScript is pretty straight forward, just declare the variable name equal to empty square brackets, like this:
var rack = [];
To add variables, you just specify the index you want to add the data to, like this:
rack[0] = "First"; rack[1] = "Second"; rack[2] = 3;
However, in PHP you can add info to the list without having to declare the ‘index’ number… (that’s the number in the square brackets)… i.e.
rack[] = "next in the list; rack[] = "and another";
But in JavaScript, it doesn’t work…. So here’s a nice solution from Sitepoints Kevin Yank…
rack[rack.length] = "next in list";
Using .length we can get the number of items in the array, but in a format where the first item is number 1… When declaring the array key, we need to start the numbering at zero, the the example above will always add the new value to the end on the array list….