pop Function:
Removes the last element from an array and returns that element. This method changes the length of the array.
Syntax:
arrayname.pop()
Example in HEAD Section:
<html> <head> <title>pop function</title> <script language="javascript"> myfish = ["Onion", "Bannana"," Orange", "Apple"]; document.write("<b>Before my Array is:</b> " + myfish +"<br>"); document.write("<b>Remove element in the array is:</b> " + myfish.pop()); document.write("<br><b>After my Array is:</b> " + myfish); </script> </head> </html> |
Example in BODY Section:
<html> <head> <title>pop function</title> </head> <body> <script language="javascript"> myfish = ["Onion", "Bannana"," Orange", "Apple"]; document.write("<b>Before my Array is:</b> " + myfish +"<br>"); document.write("<b>Remove element in the array is:</b> " + myfish.pop()); document.write("<br><b>After my Array is:</b> " + myfish); </script> </body> </html> |
OUTPUT:
Before my Array is: Onion,Bannana,Orange,Apple
Remove element in the array is: Apple
After my Array is: Onion,Bannana,Orange
No comments:
Post a Comment