javascript sort an array of objects by value code example
Example 1: javascript sort array with objects
var array = [
{name: "John", age: 34},
{name: "Peter", age: 54},
{name: "Jake", age: 25}
];
array.sort(function(a, b) {
return a.age - b.age;
}); // Sort youngest first
Example 2: sort array of objects javascript
list.sort((a, b) => (a.color > b.color) ? 1 : -1)
Example 3: sort array of objects in ascending order in js
homes.sort(function(a, b) {
return parseFloat(a.price) - parseFloat(b.price);
});