The function of the javascript push() method is to add one or more elements to the end of the array and return the new length. Its usage syntax is "array.push(item1, item2, ..., itemX) ", where parameter item1 represents the element to be added to the array.
The operating environment of this article: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
What does the javascript push() method do?
javascript push() method
The push() method adds one or more elements to the end of the array and returns the new length.
The syntax is:
array.push(item1, item2, ..., itemX)
Parameters item1, item2, ..., itemX are required. The element to add to the array.
Return value: Number New array length
Example:
Add more than one element
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi","Lemon","Pineapple")
Output
Banana,Orange,Apple,Mango,Kiwi,Lemon,Pineapple
Note: New element will be added at the end of the array. This method changes the length of the array.
Tip: To add elements at the beginning of the array, please use the unshift() method.
Recommended study: "javascript basic tutorial"
The above is the detailed content of What does the javascript push() method do?. For more information, please follow other related articles on the PHP Chinese website!