Home >Web Front-end >JS Tutorial >How to use push method in javascript
The push method in JavaScript can 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)".
The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer
How to use the push method in javascript?
JavaScript push() method
The push() method adds one or more elements to the end of the array and returns the new length.
Note: New elements will be added at the end of the array.
Note: This method changes the length of the array.
Tip: Please use the unshift() method to add elements at the beginning of the array.
All major browsers support push().
Syntax
array.push(item1, item2, ..., itemX)
Parameter values
Parameters
item1, item2, ..., itemX Required. The element to add to the array.
Recommended study: "javascript basic tutorial"
The above is the detailed content of How to use push method in javascript. For more information, please follow other related articles on the PHP Chinese website!