JavaScript Arrays
https://www.dofactory.com/javascript/arrays
JavaScript Arrays
How to creating arrays in JavaScript
// empty array with no elementsvar empty = []; // array with 2 string elementsvar days = ["Sunday", "Monday"]; // array with elements of different typesvar mixed = [false, 2.70, "Hello"]; // elements can be arbitrary expressionsvar suffix = "tree";var trees = ["Oak" + suffix, "Elm" + suffix]; // 2 dimensional array with object literalsvar array2 = [[1,{x:1, y:2}], [2, {x:3, y:4}]]; // the 3rd element is undefinedvar colors = ["Red", "Green", undefined]; // no value in the 1st element, it is undefinedvar hobbies = [,"Art"]; Accessing array elements
var days = ["Sunday", "Monday"]; // an array with 2 elementsvar firstDay = days[0]; // index 0 is converted to "0"days[1] = "Ford"; days[2] = "Tuesday"; // writes element 3var cars = ["Toyota"];cars["tires"] = 4;alert(cars["tires"]); // => 4Iterating over JavaScript arrays
The length of JavaScript arrays
Iterating over array elements
Multi-Dimensional Arrays
Deleting array elements with delete
Array methods: splice(), push(), pop(), shift(), unshift()
A versatile splice() method
Implementing a LIFO stack with push() and pop()
Implementing a FIFO queue with unshift() and shift()
Manipulating arrays with map(), filter(), reduce()
Transforming array elements with map()
Filtering the array using filter()
Last updated