Home > Article > Web Front-end > How to use pop method
The function of the pop method is to delete the last element from the array and return the element. Its usage syntax is "array.pop();". This method can also reduce the length or size of the array by one.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
The pop() method of Javascript array can remove the last element from the array and return that element. In this way, the length or size of the array will also be reduced by one. Let's take a closer look at the use of the pop method in How to use pop method.
Let’s first look at the basic syntax of the pop method
array.pop();
Then let’s look at specific examples of using the pop method
The code is as follows
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <script type="text/javascript"> var scripts = new Array(); scripts[0] = "PHP"; scripts[1] = "ASP"; scripts[2] = "How to use pop method"; scripts[3] = "HTML"; document.write(scripts.join(" <br> ")); document.write("<br>--使用pop()方法后的结果--<br>"); scripts.pop(); document.write(scripts.join(" <br> ")); </script> </body> </html>
The display effect on the browser is as follows
The last element HTML is deleted from the array.
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 pop method. For more information, please follow other related articles on the PHP Chinese website!