Return to Kroll Design home page

JavaScript Tutorials

 
« Return

pop method for arrays

The pop method removes the last element of an array, and returns it also.

Code:

<script type="text/javascript">
//<![CDATA[
myArray = new Array("one", "two", "three"); document.write("myArray before being popped:<br>"); for (i=0; i<myArray.length; i++) { document.write("myArray[", i, "] : ", myArray[i], "<br>"); } poppedElement = myArray.pop(); document.write("<br>", "poppedElement : ", poppedElement, "<br><br>"); document.write("myArray after being popped:<br>"); for (i=0; i<myArray.length; i++) { document.write("myArray[", i, "] : ", myArray[i], "<br>"); } //]]> </script>

Output:



 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM