sort array of objects on name code example
Example 1: javascript sort array of objects by key value
arr.sort((x, y) => x.distance - y.distance);
Example 2: javascript sort array of object by property
function 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.