Collections
Represent an ordered sequence of values for iteration and indexed access.
JavaScript · Class
The JavaScript Array object stores an ordered collection of values under one variable name. Arrays are zero-indexed, resizable, can mix value types, and provide methods for common collection operations.
JavaScript's Array object represents an ordered, indexed collection. Arrays can resize, hold values of different types, and provide instance methods plus static helpers for common operations; indexing starts at zero, and standard copying operations produce shallow copies.
new Array(element0, element1, /* … , */ elementN)
Array(element0, element1, /* … , */ elementN)
[element0, element1, /* … , */ elementN]Array instances are returned by the constructor and conversion helpers; individual members return operation-specific values.
array.length - 1.Array() or using array-literal syntax creates an Array object.Array.from() converts supported iterable or array-like input into a new array.Array.isArray(value) is the direct built-in test for whether a value is an Array.const values = [1, 2, 3];
const doubled = values.map((value) => value * 2);
console.log(doubled); // [2, 4, 6]
console.log(values[0]); // 1Creates an array, transforms each element into a new array, and accesses the first element by its zero-based index.
Represent an ordered sequence of values for iteration and indexed access.
Transform or filter records while preserving a collection-oriented workflow.
Convert iterable or array-like input into a conventional JavaScript array.
Array is an object representing a collection of multiple items under one variable name. It is zero-indexed, resizable, and may contain values of different types.
Follow-up: How would you avoid shared nested state when copying an array? Use an explicit deep-copy strategy; ordinary array-copy operations are shallow.
The first element is at index 0, and the last element is at length - 1. Accessing an element uses bracket notation, such as items[0].
Follow-up: What happens when the requested index is outside the populated range? The result is undefined, rather than an associative lookup by an arbitrary string.
Array.from() creates a new Array instance from an iterable or array-like object. Array.isArray() returns true for arrays and false otherwise.
Follow-up: Why can Array.from() still leave nested objects shared? The resulting array is a shallow copy of the referenced values.
Array()Array.from()Array.fromAsync()Array.isArray()Array.prototype.concat()Array.prototype.every()Array.prototype.find()Array.prototype.indexOf()