- The new items are added to the end of the variable.
Tip: while unshift() method has a similar function, it adds items to the beginning of the array.
Syntax and Usage
The syntax rules for this method are very simple. See it for yourself:
array.push(item1, item2, ...)
The following example illustrates how a new element (
Rover) is to be added to the
cars array. Analyze the full code by clicking the Try it Live button:
var cars = ["Audi", "BWM", "Mercedes", "Porsche"]; cars.push("Rover");