how to sort an array of objects by a property value in javascript sort array of objects by string property value javascript sort array of object by property sort array of objects by string property value

The solution for “how to sort an array of objects by a property value in javascript sort array of objects by string property value javascript sort array of object by property sort array of objects by string property value” can be found here. The following code will assist you in solving the problem.

let x = list.sort((a, b) => (a.name > b.name ? 1 : -1));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-zfunction sortByDate( a, b ) {
if ( a.created_at < b.created_at ){ return -1; } if ( a.created_at > b.created_at ){
return 1;
}
return 0;
}

myDates.sort(sortByDate);//myDates is not sorted.function compare( a, b ) {
if ( a.last_nom < b.last_nom ){ return -1; } if ( a.last_nom > b.last_nom ){
return 1;
}
return 0;
}

objs.sort( compare );

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in