The elements in the array are rearranged into reverse order. The Array object is returned as the result.
Note that the reverse() method may possibly be applied to other object types. Host objects may support the reverse() method, but it will be in an implementation dependant manner.
The result of this method is the array with its elements in reversed order.
<HTML> <HEAD> </HEAD> <BODY> <SCRIPT> // Demonstrate array joins myString1 = "This is a sentence made of words."; document.write("Original input string<BR>") document.write(myString1) myArray = myString1.split(" "); document.write("<BR><BR>String split into an array<BR>") displayArrayAsTable(myArray); myArray.reverse(); document.write("<BR><BR>Array reversed<BR>") displayArrayAsTable(myArray); myString2 = myArray.join(" "); document.write("<BR><BR>Array joined up as a string<BR>") document.write(myString2) // 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>") } </SCRIPT> </BODY> </HTML>
See also: | Array.prototype |
Prev | Home | Next |
Array.push() | Up | Array.shift() |
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. |