Array Sort Numeri e lettere





https://www.w3schools.com/js/tryit.asp?filename=tryjs_array_sort_alpha

' sort the array alphabetically or numerically.



<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array Sort</h2>

<p>Click the buttons to sort the array alphabetically or numerically.</p>

<button onclick="myFunction1()">Sort Alphabetically</button>
<button onclick="myFunction2()">Sort Numerically</button>

<p id="demo"></p>

<script>
var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = points;

function myFunction1() {
points.sort();
document.getElementById("demo").innerHTML = points;
}
function myFunction2() {
points.sort(function(a, b){return a - b});
document.getElementById("demo").innerHTML = points;
}
</script>

</body>
</html>










( arraysortnumerielettere.html )- by Paolo Puglisi - Modifica del 17/12/2023