JavaScript Array push() method

The JavaScript array push() method adds one or more elements to the end of the given array.

JavaScript Array push() method changes the length of the original array.

The push() method adds new items to the end of an array.

The push() method returns the new length.

The push method appends values to an array.


array.push(item1, item2, ..., itemN)


item1, item2..itemN – The elements to be added. Minimum one item is required.

Return Value

A number stating the new length of the array.


const animals = ['pigs', 'goats', 'sheep'];

const count = animals.push('cows');
// expected output: 4
// expected output: Array ["pigs", "goats", "sheep", "cows"]

animals.push('chickens', 'cats', 'dogs');
// expected output: Array ["pigs", "goats", "sheep", "cows", "chickens", "cats", "dogs"]

let sports = ['soccer', 'baseball']
let total = sports.push('football', 'swimming')

console.log(sports)  // ['soccer', 'baseball', 'football', 'swimming']
console.log(total)   // 4
let newArray = [1, 2, 3, 4, 5].push(6)
// [1, 2, 3, 4, 5, 6]

The .push() method mutates the old array.