Home >>JavaScript Array Reference >JavaScript Array pop() Method
JavaScript array pop() methodis used to remove the last element from an array and returns the removed element and also changes the length of an array.
Syntax:array.pop()
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
pop() | 1.0 | 5.5 | 1.0 | Yes | Yes |
<html> <body> <button onclick="myPop()">click me</button> <p id="POP"></p> <script> var y = ["Red", "Blue", "Green", "Yellow"]; document.getElementById("POP").innerHTML = y; function myPop() { y.pop(); document.getElementById("POP").innerHTML = y; } </script> </body> </html>
<html> <body> <script> function popmethod() { var z = []; var popped = z.pop(); document.write(popped); } popmethod(); </script> </body> </html>