Answers for "sort in array javascript"

3

sorting of arraray's number element in javascript

let numbers = [0, 1, 2, 3, 10, 20, 30];
numbers.sort((a, b) => a - b);

console.log(numbers);
Posted by: Guest on April-17-2020
7

javascript sort

homes.sort(function(a, b) {
    return parseFloat(a.price) - parseFloat(b.price);
});
Posted by: Guest on March-17-2020
-1

sort function explained javascript

var sortedArray = myArray.sort(function(a,b){
                                   if (a.name < b.name)
                                      return -1;
                                   else if (a.name == b.name)
                                      return 0;
                                   else
                                      return 1;
                               });
Posted by: Guest on June-25-2020
-3

mdn array sort

arr.sort([compareFunction])
Posted by: Guest on November-05-2020

Browse Popular Code Answers by Language