The shift method removes the first element from an array, and also returns that element.
Code:
<script type="text/javascript"> //<![CDATA[
myArray = new Array("a","b","c","d","e"); document.write("myArray before the shift method is applied:<br>"); for (i=0; i<myArray.length; i++) { document.write("myArray[", i, "] : ", myArray[i], "<br>"); } document.write("<br>"); returnedElement = myArray.shift(); document.write("returnedElement: ", returnedElement, "<br><br>"); document.write("myArray after the shift method is applied:<br>"); for (i=0; i<myArray.length; i++) { document.write("myArray[", i, "] : ", myArray[i], "<br>"); } //]]> </script>
Output: