A list that keeps several pieces of data in order.
Arrays are helpful for storing related data. They can contain data of any type. For example, an array could contain a list of someone's favorite colors as strings. Arrays are created as follows:
let myArray = ['deeppink', 'darkorchid', 'magenta'];
Each piece of data in an array is called an element. Each element has an address, or index, within its array. The variable myArray refers to an array with three String elements, 'deeppink', 'darkorchid', and 'magenta'. Arrays are zero-indexed, which means that 'deeppink' is at index 0, 'darkorchid' is at index 1, and 'magenta' is at index 2. Array elements can be accessed using their indices as follows:
let zeroth = myArray[0]; // 'deeppink'
let first = myArray[1]; // 'darkorchid'
let second = myArray[2]; // 'magenta'
Elements can be added to the end of an array by calling the push() method as follows:
myArray.push('lavender');
let third = myArray[3]; // 'lavender'
See MDN for more information about arrays.
Examples
Related References
stringify
From the MDN entry: The JSON.stringify() method converts a JavaScript object or value to a JSON string.
log
Prints a message to your browser's web console.
===
The strict equality operator === checks to see if two values are equal and of the same type.
Array
A list that keeps several pieces of data in order.