Java Script Arrays -POP Method



To Remove the Last element of An Array this pop Method is used .


 <!DOCTYPE html>  
 <html>  
 <body>  
 <button onclick="myFunction()">Try it</button>  
 <p id="demo"></p>  
 <script>  
   var fruits = ["Banana", "Orange", "Apple", "Mango"];  
   document.getElementById("demo").innerHTML = fruits;  
   function myFunction() {  
     fruits.pop();  
     document.getElementById("demo").innerHTML = fruits;  
   }  
 </script>  
 </body>  
 </html>  
Example Explained :

When user clicks on the button the myFunction is called .

inside the myFunction() pop() method will be executed which will remove the last element of the Array.  After removing it will access the div with id of demo and insert the array elements

Comments

Popular posts from this blog

HTML Attributes ....

How to Study Web Developement Course