Array.reverse() Method : Array « Language Basics « JavaScript DHTML






Array.reverse() Method

  
<HTML>
<HEAD>
<TITLE>Array.reverse()</TITLE>
<SCRIPT LANGUAGE="JavaScript1.1">
solarSys = new Array(9)
solarSys[0] = "M"
solarSys[1] = "V"
solarSys[2] = "E"
solarSys[3] = "M"
solarSys[4] = "J"
solarSys[5] = "S"
solarSys[6] = "U"
solarSys[7] = "N"
solarSys[8] = "P"


function showAsIs(form) {
    var delimiter = form.delim.value
    form.output.value = unescape(solarSys.join(delimiter))
}


function reverseIt(form) {
    var delimiter = form.delim.value
    solarSys.reverse()  
    form.output.value = unescape(solarSys.join(delimiter))
}
</SCRIPT>
<BODY>
<H2>Reversing array element order</H2>
<FORM>
Enter a string to act as a delimiter between entries:
<INPUT TYPE="text" NAME="delim" VALUE="," SIZE=5><P>
<INPUT TYPE="button" VALUE="Array as-is" onClick="showAsIs(this.form)">
<INPUT TYPE="button" VALUE="Reverse the array" onClick="reverseIt(this.form)">
<INPUT TYPE="reset">
<INPUT TYPE="button" VALUE="Reload" onClick="self.location.reload()">
<TEXTAREA NAME="output" ROWS=4 COLS=60>
</TEXTAREA>
</FORM>
</BODY>
</HTML>


           
         
    
  








Related examples in the same category

1.Demo all methods in Array
2.Assing array value inside function
3.Simple Array Demo
4.Array loop, find:Control array : Two dimension array
5.Reversing, Sorting, and Concatenating an Array
6.Custom Numeric Comparison for the Array.Sort Method
7.Case-Insensitive Comparison for the Array.Sort Method
8.Iterating Through a Sparse Array
9.Using Functions to Iterate Through an Array
10.Reading and Writing Array Elements
11.Array with a numeric parameter and assign data to it
12.A string array
13.Array - properties and methods:length, join, reverse, push,pop,shift
14.Array - sort()
15.Array - concat and slice
16.Array - splice
17.Methods and Properties of the Array Object
18.Displaying the Contents of an Array
19.Using the Array.join() Method
20.Using JavaScript Arrays
21.Extending the Length of an Array
22.An Array within an Array
23.Using the Methods of the Array object
24.Array.sort() Possibilities
25. Array Concatenation
26.A Looping Array Lookup
27.A Simple Parallel Array Lookup
28.Adding a prototype Property
29.Two-Dimensional Array Work Around
30.Array definition and iteration
31.Reference an Array by index
32.URL Array
33.Array Utility functions
34.Dynamic array
35.Use for loop to display elements in an array
36.A string array variable
37.Queue based on array