how to sort an array of objects by a property value in javascript
let x = list.sort((a, b) => (a.name > b.name ? 1 : -1));
how to sort an array of objects by a property value in javascript
let x = list.sort((a, b) => (a.name > b.name ? 1 : -1));
javascript sort array by object property
function compareFirstNames( a, b ) {
if ( a.first_name < b.first_name ){
return -1;
}
if ( a.first_name > b.first_name ){
return 1;
}
return 0;
}
var people =[
{"first_name":"Carol", "age":29},
{"first_name":"Anna", "age":32},
{"first_name":"Bob", "age":32}
];
people.sort( compareFirstNames ); //people is now sorted by first name from a-z
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us