JavaScript - Array pop() Method


Advertisements


Description

Javascript array pop() method removes the last element from an array and returns that element.

Syntax

Its syntax is as follows −

array.pop();

Return Value

Returns the removed element from the array.

Example

Try the following example.

<html>
   <head>
      <title>JavaScript Array pop Method</title>
   </head>
   
   <body>
   
      <script type="text/javascript">
         var numbers = [1, 4, 9];
         
         var element = numbers.pop();
         document.write("element is : " + element ); 
         
         var element = numbers.pop();
         document.write("<br />element is : " + element );
      </script>
      
   </body>
</html>

Output

element is : 9
element is : 4  

javascript_arrays_object.htm

Advertisements