Home > Article > Web Front-end > How to use push method
The push method is to add the given element to the last element of the array and return the length of the new array. Its usage syntax is "array.push(element1, ..., elementN);".
The operating environment of this article: Windows 7 system, Dell G3 computer, javascript version 1.8.5.
The push() method of Javascript array adds the given element to the last element of the array and returns the length of the new array. Let’s take a look at the specific use of the push method.
Let’s first take a look at the basic syntax of the push() method
array.push(element1, ..., elementN);
element1,..., elementN represents the element to be added to the end of the array.
Next let’s look at the specific usage examples of the push method
The code is as follows
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <script type = "text/javascript"> var numbers = new Array(1, 4, 9); var length = numbers.push(10); document.write("new numbers is : " + numbers ); length = numbers.push(20); document.write("<br />new numbers is : " + numbers ); </script> </body> </html>
The display effect on the browser is as follows:
This article ends here. For more exciting content, you can pay attention to the relevant column tutorials on the php Chinese website! ! !
The above is the detailed content of How to use push method. For more information, please follow other related articles on the PHP Chinese website!