0

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>Sort in Reverse</h2>

<p>The reverse() method reverses the elements in an array.</p>
<p>By combining sort() and reverse() you can sort an array in descending order:</p>

<p id="workingcode1"></p>
<p id="workingcode2"></p>

<script>
// Create and display an array:
const hero = ["Antman","Spiderman","superman","Wonderwoman"];
document.getElementById("workingcode1").innerHTML = hero;

// First sort the array
hero.sort();

// Then reverse it:
hero.reverse();

document.getElementById("workingcode2").innerHTML = hero;
</script>

</body>
</html>

Output
JavaScript Arrays
Sort in Reverse
The reverse() method reverses the elements in an array.

By combining sort() and reverse() you can sort an array in descending order:

Antman,Spiderman,superman,Wonderwoman

superman,Wonderwoman,Spiderman,Antman

Reversing an array in javascript
admin Changed status to publish December 26, 2023