Changing the order of elements of an array by reverse() function

We can reverse the order of the element by using the reverse method. Here the first element will became last method and last element became first and other elements will also change their positions.

We have created an array of scripts and then displayed the elements. Then we have applied the command scripts.reverse(); to our scripts array and displayed again all the elements to see the result of reverse() function.

Here is the code to reverse the array elements.

Demo of Array reverse

<script type="text/javascript">
var scripts = new Array();
scripts[0] = "PHP";
scripts[1] = "ASP";
scripts[2] = "JavaScript";
scripts[3] = "HTML";
document.write(scripts.join(" <br> "));
document.write("<br>- after reverse---<br>");
document.write(scripts.join(" <br> "));

Post your comments , suggestion , error , requirements etc here .

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2021 All rights reserved worldwide Privacy Policy Disclaimer