sort array elements javascript code example
Example 1: sort arrays according to first array js
itemsArray.sort(function(a, b){
return sortingArr.indexOf(a) - sortingArr.indexOf(b);
});
Example 2: javascript sort
homes.sort((a, b) => parseFloat(a.price) - parseFloat(b.price));
Example 3: javascript sort array in ascending order
//sorts arrays of numbers
function myFunction() {
points.sort(function(a, b){return a-b});
document.getElementById("demo").innerHTML = points;
}