| reverse() This method is used to reverse the items within the given array according to the array placement (index) numbers. The top-most array items will become the bottom-most, and the bottom-most will become the top-most. syntax: Array.reverse() arrayName.reverse() EXAMPLE var reverseArray = new Array(10, 20, 30); document.write("The array contents are : " + reverseArray[0] + ", " + reverseArray[1] + ", " + reverseArray[2] + ". "); reverseArray.reverse(); document.write("The array contents are now : " + reverseArray[0] + ", " + reverseArray[1] + ", " + reverseArray[2] + "."); The example starts with the creation of an array with three items, 10, 20, and 30. The contents are then written to the screen through the use of a document.write statement. The contents of the array are then reversed with the reverse() method, and the document.write statement then writes the shuffled contents of the array, now reversed in order. The output looks like the following: The array contents are : 10, 20, 30. The array contents are now : 30, 20, 10. |