order list of objects javascript code example
Example 1: sort array of objects javascript
list.sort((a, b) => (a.color > b.color) ? 1 : -1)
Example 2: js sort array of objects
const drinks1 = [
{name: 'lemonade', price: 90},
{name: 'lime', price: 432},
{name: 'peach', price: 23}
];
function sortDrinkByPrice(drinks) {
return drinks.sort((a, b) => a.price - b.price);
}