参考 Array

Array

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.

示例

Notice any errors or typos? Please let us know. Please feel free to edit src/core/reference.js and open a pull request!

相关参考