The sort() sorts the elements of an array.
The sort() overwrites the original array.
The sort() sorts the elements as strings in alphabetical and ascending order.
array.sort()
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var a = ["Umar","Zaid","Rehman","Hamza"];
document.write(a + "<br><br>");
a.sort();
document.write(a);
</script>
</head>
<body>
</body>
</html>
The reverse() method reverses the order of the elements in an array.
The reverse() method overwrites the original array.
array.reverse()
The array after it has been reversed. |
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var b = ["Uamr", "Zaid", "Rehman", "Hamza"];
document.write(b + "<br><br>");
b.reverse();
document.write(b);
</script>
</head>
<body>
</body>
</html>