let strArray = [{name: 'c' }, {name: 'a' }, {name: 'd' }, {name: 'b' }];
console.log(strArray.sort((a, b) => a.name.localCompare(b.name)))
// nodejs
console.log(strArray.sort((a, b) => a.name.localeCompare(b.name)))
obj.sort(function(a,b){
if(a.last_nom< b.last_nom) return -1;
if(a.last_nom >b.last_nom) return 1;
if(a.first_nom< b.first_nom) return -1;
if(a.first_nom >b.first_nom) return 1;
return 0;
});
function dynamicSort(property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
/* next line works with strings and numbers,
* and you may want to customize it to your needs
*/
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
}