JavaScript tutorial:
reverse method

Applies to: Array Object

The reverse method is use to reverse all the elements in the array.

Syntax

arrayobj.reverse( )

Return Array

Returns an Array object with the elements reversed.

Example

The reverse method reverses the elements of an Array object in place. It does not create a new Array object during execution.

If the array is not contiguous, the reverse method creates elements in the array that fill the gaps in the array. Each of these created elements has the value undefined.

The following example illustrates the use of the reverse method:

a = new Array(1,2,3,4,5);
l = a.reverse();

document.write(l);

To run the code above, paste it into JavaScript Editor, and click the Execute button

See also: Array Object Methods