The value as added to the end of the array.
If the value is an array itself, it is not flattened. When it is eventually popped, you get the array back.
If several values are passed to the push() method, they will all be added to the stack, but only the last one will be returned.
This modifies the receiving array, increasing the array length by the number of elements that were pushed onto the end.
The result of this method is the new length of the receiving array after the pushed item has been concatenated onto its tail.
// Create an array and test the Array.push() method myArray = new Array("AAA", "BBB", "CCC"); document.write("Array<BR>") displayArrayAsTable(myArray); document.write("Array.push()<BR>") document.write(myArray.push("XXX")) document.write("<BR><BR>") document.write("Array after push('XXX') 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.prototype | Up | Array.reverse() |
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. |