JS Arrays
JavaScript arrays are used to store multiple values in a single variable.
JavaScript arrays are used to store multiple values in a single variable. Arrays are a special kind of objects.
Creating an Array
Using an array literal is the easiest way to create a JavaScript Array.
const array_name = [item1, item2, ...];
Preview
Accessing Array Elements
You access an array element by referring to the index number. Array indexes start with 0.
[0] is the first element. [1] is the second element.
Preview
Changing an Array Element
You can also assign a new value to an array index.
Preview
Array Properties and Methods
The real strength of JavaScript arrays are the built-in array properties and methods.
lengthProperty: Returns the number of elements in an array.push()Method: Adds a new element to an array (at the end).pop()Method: Removes the last element from an array.
Preview