Home > Article > Web Front-end > How to use pop() method
javascript pop() method can be used to delete the last element in a JavaScript array and return the number of deleted elements.
javascript pop() method
Function:pop() method Used to remove and return the last element of an array.
Basic syntax:
arrayObject.pop()
Note: pop() method will change the length of the array.
Description: The pop() method will delete the last element of arrayObject, reduce the array length by 1, and return the value of the element it deletes. If the array is already empty, pop() does not modify the array and returns undefined.
Usage example of javascript pop() method
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body style="font-size:20px ;"> <script type="text/javascript"> var arr = new Array(3) arr[0] = "PHP" arr[1] = "Javascript" arr[2] = "MySQL" arr[3] = "Python" document.write("原数组:"+arr) document.write("<br/><br/>") document.write("删除的元素:"+arr.pop()) document.write("<br/><br/>") document.write("新数组:"+arr) </script> </body> </html>
Rendering:
The above is the entire content of this article, I hope it will be helpful to everyone's study.
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!