Array reverse() Method - Javascript Array

Javascript examples for Array:reverse

Description

The reverse() method reverses the order of the elements in an array.

Parameters

None

Return Value:

An Array reversed

The following code shows how to Reverse the order of the elements in an array:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
var fruits = ["a","b","c","d","e"];
document.getElementById("demo").innerHTML = fruits;

function myFunction() {/* ww  w.  j ava 2 s .co  m*/
    fruits.reverse();
    document.getElementById("demo").innerHTML = fruits;
}
</script>

</body>
</html>

Related Tutorials