Menu ▼



Posted By :
avatarmrkraju
Total Views : 435

JavaScript array reverse

JavaScript inbuilt array reverse() method reverses the order of the elements in an array (original array will be reversed).

Example
Original Array: var ary = ["One", "Two", "Three", "Four", "Five"];



Output


Syntax
document.getElementById("snpresult").innerText = ary.reverse();

Source code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
<script language="javascript">
    var ary = ["One", "Two", "Three", "Four", "Five"];
    function reverseArray() {
        document.getElementById("snpresult").innerText = ary.reverse();
    }
</script>
</head>
<body>
Original Array:
var ary = ["One", "Two", "Three", "Four", "Five"];
<br />
<br />
<input type="button" onclick="reverseArray();" value="Print Reverse Array" />
<br />
<br />
<span id="snpresult"></span>
</body>
</html>





comments powered by Disqus


Search dotnetlearners.com