JavaScript Tutorial/Array/Reverse

Материал из Web эксперт
Перейти к: навигация, поиск

Array.reverse()

The reverse() method reverses the order of the elements in the array according to the array index numbers.



<html>
    <script language="JavaScript">
    <!--
    lineOfPeople = new Array("A","B","C");
    lineOfPeople.reverse();
    document.write("lineOfPeople[0]=",lineOfPeople[0],"<br>");
    document.write("lineOfPeople[1]=",lineOfPeople[1],"<br>");
    document.write("lineOfPeople[2]=",lineOfPeople[2],"<br>");
    -->
    </script>
</html>


Reverse the elements in an Array

<html>
<head>
<title>Reverse an Array</title>
<script language="javascript" type="text/javascript">
<!--
var x = new Array(2,3,4);
x.reverse();
alert(x);
//-->
</script>
</head>
<body>
</body>
</html>