HTML CSS Bootstrap Javascript Icons Python
JavaScript Reference
Overview
JS Reference
JS Array Object JS Boolean Object JS Date Object JS Style Declaration Object JS Error Object JS Global Object JS Math Object JS Number Object JS String Object JS RegExp Object JS Statements
DOM Reference
DOM Attribute DOM Console DOM Document DOM Element DOM Events DOM Event Objects DOM History DOM HTMLCollection DOM Location DOM Navigator DOM Screen DOM Style DOM Window WEB Storage

JavaScript Array Reference

The Array Object

An Array is used to store multiple values in a single variable.

The JavaScript Array object is a global object that is used in the construction of arrays.

Run code

JavaScript arrays are zero-indexed: the first element of an array is at index 0, the second is 1, and so on.

The last element is at the index equal to the value of the array's length property minus 1.

Using an invalid index number returns undefined.

You can learn more about Arrays in our JavaScript Array Tutorial.


Array Object Properties

The following table lists the standard properties of the Array object:

Property Description
constructor Returns the function that created the Array object's prototype
length Sets or returns the number of elements in an array
prototype Allows you to add new properties and methods to an Array object

Array Object Methods

The following table lists the standard methods of the Array object:

Method Description
concat() Merge two or more arrays, and returns a new array
copyWithin() Copies a sequence of array elements within the array
entries() Returns a key/value pair Array Iteration Object
every() Checks if every element in an array pass a test in a testing function
fill() Fill the elements in an array with a static value
filter() Creates a new array with all elements that pass the test in a testing function
find() Returns the value of the first element in an array that pass the test in a testing function
findIndex() Returns the index of the first element in an array that pass the test in a testing function
forEach() Calls a function once for each array element
from() Creates an array from an object
includes() Determines whether an array includes a certain element
indexOf() Search the array for an element and returns its first index
isArray() Determines whether the passed value is an array
join() Joins all elements of an array into a string
keys() Returns a Array Iteration Object, containing the keys of the original array
lastIndexOf() Search the array for an element, starting at the end, and returns its last index
map() Creates a new array with the results of calling a function for each array element
pop() Removes the last element from an array, and returns that element
push() Adds one or more elements to the end of an array, and returns the array's new length
reduce() Reduce the values of an array to a single value (from left-to-right)
reduceRight() Reduce the values of an array to a single value (from right-to-left)
reverse() Reverses the order of the elements in an array; the first becomes the last, and the last becomes the first
shift() Removes the first element from an array, and returns that element
slice() Extracts a part of an array, and returns the new array
some() Checks if any of the elements in an array passes the test in a testing function
sort() Sorts the elements of an array
splice() Adds/Removes elements from an array
toString() Converts an array to a string, and returns the result
unshift() Adds new elements to the beginning of an array, and returns the array's new length
valueOf() Returns the primitive value of an array