Arrays in JavaScript are a special type of object. They resemble Python Lists (an ordered and changeable collection, allowing duplicate members and members of different types).
You can use the bracket notation to access and modify the array elements.
You can create an empty array and then add values to it:
You can make an empty array using array constructor syntax:
But it is more common to use the array literal syntax instead:
Madness: In an array, you can leave some elements undefined!
Note how the trailing comma does not denote an undefined element!
Allowing undefined elements leads to more annoying behaviors.
length is calculated as one more than the highest index!
And the craziest thing is that you can overwrite the length property!
Destructuring Arrays
Convenient syntax for fetching multiple elements:
You can even do this:
Multi-dimensional arrays
Use arrays of arrays for multi-dimensional arrays:
Array object comes with many useful built-in operations. We will explore some of these in future lessons. For the impatient, please visit Array on MDN web docs.