Favorites

JavaScript Array Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Array
JavaScript Indexed Collections · ConstructorThis object is supported by all modern browsers.
Updated 28th November 2026

The Array object stores an ordered list of values that you access by their index, starting at 0. It comes with methods for adding, removing, searching, sorting and transforming items.

Description

The Array object holds an ordered collection of values, called elements, which you access by a numeric index starting at 0. Arrays can hold values of any type, including other arrays and objects, and they grow and shrink automatically as you add or remove elements. The Array.prototype.length property always gives the number of elements.

Arrays are usually created with an array literal, such as [1, 2, 3]. The Array() constructor also works, but a single number argument creates an empty array of that length rather than an array containing the number, which often surprises people. To create an array from something array-like, such as a string or a NodeList, use Array.from().

Many array methods, such as Array.prototype.map(), filter() and slice(), return a new array and leave the original unchanged. Others, such as push(), sort() and splice(), change the array in place. Newer methods such as toSorted() and toReversed() give copying versions of the ones that mutate. Arrays are objects, so typeof returns "object"; use Array.isArray() to check for one.

Creating

[element1, element2, ...]
new Array(element1, element2, ...)
new Array(length)

Static methods

NameDescription
Array.from()The Array.from() static method creates a new array from an iterable or array-like object, such as a string, Set or NodeList, optionally mapping each element.
Array.isArray()The Array.isArray() static method checks whether a value is an array, returning true or false.
Array.of()The Array.of() static method creates a new array from its arguments, avoiding the single-number quirk of the Array() constructor.

Instance properties

NameDescription
Array.prototype.lengthThe length property gives the number of elements in an array.

Instance methods

NameDescription
Array.prototype.at()The at() method returns the element at a given index, and accepts negative numbers to count back from the end of the array.
Array.prototype.concat()The concat() method joins arrays and values into a new array, leaving the originals unchanged.
Array.prototype.entries()The entries() method returns an iterator of [index, element] pairs, which is handy for getting the index in a for...of loop.
Array.prototype.every()The every() method checks whether all elements of an array pass a test, returning true or false.
Array.prototype.fill()The fill() method sets all or part of an array to one value, changing the array in place.
Array.prototype.filter()The filter() method creates a new array with only the elements that pass a test you provide.
Array.prototype.find()The find() method returns the first element in an array that passes a test, or undefined if no element does.
Array.prototype.findIndex()The findIndex() method returns the index of the first element that passes a test, or -1 if no element does.
Array.prototype.findLast()The findLast() method searches an array from the end and returns the last element that passes a test.
Array.prototype.findLastIndex()The findLastIndex() method returns the index of the last element in an array that passes a test, or -1.
Array.prototype.flat()The flat() method creates a new array with nested arrays flattened into it, up to a given depth.
Array.prototype.flatMap()The flatMap() method maps each element with a function and flattens the result by one level, letting one element become several or none.
Array.prototype.forEach()The forEach() method runs a function once for each element of an array.
Array.prototype.includes()The includes() method checks whether an array contains a certain value, returning true or false.
Array.prototype.indexOf()The indexOf() method returns the first index at which a value is found in an array, or -1 if it isn't there.
Array.prototype.join()The join() method combines all elements of an array into a single string, with a separator of your choice between them.
Array.prototype.keys()The keys() method returns an iterator over the indexes of an array.
Array.prototype.lastIndexOf()The lastIndexOf() method returns the last index at which a value is found in an array, or -1.
Array.prototype.map()The map() method creates a new array by calling a function on every element of an array and collecting the results.
Array.prototype.pop()The pop() method removes the last element from an array and returns it, changing the array's length.
Array.prototype.push()The push() method adds one or more elements to the end of an array and returns the new length.
Array.prototype.reduce()The reduce() method combines all elements of an array into a single value, such as a total, by calling a function that carries a running result from one element to the next.
Array.prototype.reduceRight()The reduceRight() method works like reduce() but processes the array from the last element to the first.
Array.prototype.reverse()The reverse() method reverses the order of the elements of an array in place.
Array.prototype.shift()The shift() method removes the first element of an array and returns it, moving the other elements down.
Array.prototype.slice()The slice() method returns a copy of part of an array, from a start index up to an end index, without changing the original.
Array.prototype.some()The some() method checks whether at least one element of an array passes a test, returning true or false.
Array.prototype.sort()The sort() method sorts the elements of an array in place.
Array.prototype.splice()The splice() method changes an array in place by removing, replacing or inserting elements at a given position.
Array.prototype.toReversed()The toReversed() method returns a reversed copy of an array, leaving the original unchanged.
Array.prototype.toSorted()The toSorted() method returns a sorted copy of an array, leaving the original unchanged.
Array.prototype.toSpliced()The toSpliced() method returns a copy of an array with elements removed, replaced or inserted, leaving the original unchanged.
Array.prototype.toString()The toString() method returns a string of an array's elements separated by commas.
Array.prototype.unshift()The unshift() method adds one or more elements to the start of an array and returns the new length.
Array.prototype.values()The values() method returns an iterator over the elements of an array.
Array.prototype.with()The with() method returns a copy of an array with one element replaced, leaving the original unchanged.

Example

const fruits = ['apple', 'banana'];
fruits.push('cherry');          // add to the end

console.log(fruits.length);     // 3
console.log(fruits[0]);         // first item
console.log(fruits.at(-1));     // last item

const upper = fruits.map(f => f.toUpperCase());
console.log(upper);
console.log(fruits.includes('banana'));

Browser Support

The following information will show you the current browser support for the Array object. Hover over a browser icon to see the version that first introduced support for this object.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee