JavaScript Array.prototype.push() Method
The push() method adds one or more elements to the end of an array and returns the new length.
Description
The push() method adds elements to the end of an array and returns its new length. It changes the array in place.
To add all the elements of another array, spread it: a.push(...b). If you need a new array instead of changing the existing one, as in React state updates, use [...a, item] or concat().
The return value is the new length, not the array, so you can't chain push(); write arr.push(x) as its own statement. Pushing is fast because elements are added at the end and nothing else moves. Spreading very large arrays into push(), with hundreds of thousands of items, can exceed the browser's argument limit, in which case a loop or concat() is safer.
Syntax
array.push(element1, element2, ...)Parameters
- element1, element2, ...The elements to add to the end of the array.
Return Value
The new length of the array.
Example
Browser Support
The following information will show you the current browser support for the Array.prototype.push() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





