The pop in JavaScript :- Geniusofstudent



  • By using the pop() method is remove the last element of an array, and it will return that item.
  • This method will change the length of an array.
  • It is called pop.


  • Code:-
    1. <!DOCTYPE html> 
    2. <html> 
    3.  
    4. <head> 
    5.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
    6. </head> 
    7.  
    8. <body> 
    9.  <h1>pop()</h1> 
    10.  <h2>ar=["1st","2nd","3rd","4th"]</h2> 
    11.  
    12.  <input type="button" onclick="ar_pop();" value="pop() in array"> 
    13.  
    14.  <script> 
    15.   function ar_pop() 
    16.   { 
    17.  
    18.    var ar = ["1st", "2nd", "3rd", "4th"]; 
    19.  
    20.    //Method 1 
    21.    alert("Returne : " + ar.pop()); //remove the and return the last value '4th' 
    22.    alert("After : " + ar); 
    23.  
    24.   } 
    25.  </script> 
    26.  
    27. </body> 
    28.  
    29. </html>
    The pop in JavaScript :- Geniusofstudent The pop in JavaScript :- Geniusofstudent Reviewed by Network security on July 11, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.