Please click on this link to access the resource folder for this lesson.
Arrays are used to store ordered collections.
There are two syntaxes for creating an empty array:
Array
Almost all the time, the second syntax is used. We can supply initial elements in the brackets:
Array elements are numbered, starting with zero. We can get an element by its number in square brackets:
An array can store elements of any type. Objects, functions, etc
Array Method
Array methods are functions we can call on an array
There are lots of methods built into Arrays. See full list here
You can loop over arrays with for, for…of, forEach
The length property automatically updates when we modify the array. To be precise, it is actually not the count of values in the array, but the greatest numeric index plus one.
Arrays can have items that are also arrays. We can use it for multidimensional arrays, for example to store matrices:
Arrays can have items that are also arrays. We can use it for multidimensional arrays, for example to store matrices:
Other popular array methods are map, slice, and splice