0

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The sort() Method</h2>

<p>The sort() method sorts an array alphabetically:</p>

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

<script>
const hero = ["Antman","Spiderman","superman","Wonderwoman"];
document.getElementById("workingcode1").innerHTML = hero;

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

</body>
</html>

Output
JavaScript Arrays
The sort() Method
The sort() method sorts an array alphabetically:

Antman,Spiderman,superman,Wonderwoman

Antman,Spiderman,Wonderwoman,superman

Sorting an array in Javascript
admin Changed status to publish December 26, 2023