This method pulls an item from the front of the stack and removes that item.
The array elements are all moved down one index position.
This modifies the array in place.
The result of this method is the item that is deleted from the front of the stack.
// Create an array and test the Array.shift() method
myArray = new Array("AAA", "BBB", "CCC");
document.write("Array<BR>")
displayArrayAsTable(myArray);
document.write("Array.shift()<BR>")
document.write(myArray.shift())
document.write("<BR>")
document.write("<BR>")
document.write("Array after shift() call<BR>")
displayArrayAsTable(myArray);
// Display an array in a table
function displayArrayAsTable(anArray)
{
myLength = anArray.length;
document.write("<TABLE BORDER=1>");
for(myIndex = 0; myIndex < myLength; myIndex++)
{
document.write("<TR><TD>");
document.write(myIndex);
document.write("</TD><TD>");
document.write(anArray[myIndex]);
document.write("</TD></TR>");
}
document.write("</TABLE><BR><BR>")
}| Prev | Home | Next |
| Array.reverse() | Up | Array.slice() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||