how to sort array of objects descending in javascript code example
Example 1: sort array of objects in ascending order in js
homes.sort(function(a, b) {
return parseFloat(a.price) - parseFloat(b.price);
});
Example 2: js string sort
if (item1.attr < item2.attr)
return -1;
if ( item1.attr > item2.attr)
return 1;
return 0;