C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Array pop() methodThe JavaScript array pop() method removes the last element from the given array and return that element. This method changes the length of the original array. SyntaxThe pop() method is represented by the following syntax: array.pop() ReturnThe last element of given array. JavaScript Array pop() method exampleLet's see some examples of pop() method. Example 1Here, we will pop an element from the given array. <script> var arr=["AngularJS","Node.js","JQuery"]; document.writeln("Orginal array: "+arr+"<br>"); document.writeln("Extracted element: "+arr.pop()+"<br>"); document.writeln("Remaining elements: "+ arr); </script> Output: Orginal array: AngularJS,Node.js,JQuery Extracted element: JQuery Remaining elements: AngulaJS,Node.js Example 2In this example, we will pop all the elements from the given array. <script> var arr=["AngulaJS","Node.js","JQuery"]; var len=arr.length; for(var x=1;x<=len;x++) { document.writeln("Extracted element: "+arr.pop()+"<br>"); } </script> Output: Extracted element: JQuery Extracted element: Node.js Extracted element: AngulaJS
Next TopicJavaScript Array
|