Array.prototype.push
Adds the specified elements to the end of an array and returns the new length of the array
Syntax
array.push(...elements)Parameters
| Parameter | Type | Description |
|---|---|---|
| elements | T[] | The elements to add to the end of the array |
Return Value
The new length of the array
Examples
const animals = ['pigs', 'goats'];
const count = animals.push('cows');
console.log(count); // 3
console.log(animals); // ['pigs', 'goats', 'cows']const stack: number[] = [];
stack.push(1);
stack.push(2, 3);
console.log(stack); // [1, 2, 3]const arr = [1, 2];
arr.push(...[3, 4, 5]);
console.log(arr); // [1, 2, 3, 4, 5]Understanding Array.prototype.push
The Array.prototype.push method in JavaScript adds the specified elements to the end of an array and returns the new length of the array. It belongs to the Array object and is one of the most widely used methods for working with array values in modern JavaScript and TypeScript applications.
The method signature is array.push(...elements). It accepts 1 parameter: elements. When called, it returns the new length of the array. Understanding when and how to use push() helps you write more expressive, readable code.
Common use cases for Array.prototype.push include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-pop, array-unshift, array-concat, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Array.prototype.push is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Array.prototype.popRemoves the last element from an array and returns that element, changing the length of the array
Array.prototype.unshiftAdds the specified elements to the beginning of an array and returns the new length of the array
Array.prototype.concatMerges two or more arrays into a new array without changing the existing arrays
Array.prototype.spliceChanges the contents of an array by removing or replacing existing elements and/or adding new elements in place
More Array Methods
Other methods in the Array object
Related Tools
More Array Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.