Arrays are data structures with automatically indexed positions. Array indices are zero–based.
JSLint suggests literal notation for creating arrays and objects. Allows for initializing values.
var someArray = [1, 2, 3];
var someArray = new Array();
someArray[0] = 1;
someArray[1] = 2;
someArray[2] = 3;
shift()
removes cell at first position and retrieves it's value.
pop()
removes cell at last position and retrieves it's value.
push()
adds a cell in the last postion nad enters a value.
arrayData[7] = undefined;
Use undefined
to create empty cells.
join()
turns an array into a string.
split()
turns a string into an array.
var fruits = ["Lemon","Apple","Orange","Peach"];
var str = fruits.join(', ');
alert(str); // "Lemon, Apple, Orange, Peach"
var fruits = "Apple,Orange,Peach";
var arr = fruits.split(',');
// arr is ["Apple", "Orange", "Peach"]
alert(arr[0]);