I want to sort an array of of objects in JavaScript with Two properties Boolean value and Int value.I want want Output like this :
{ first_nom: 'sumeet', last_nom: 'Prentice' ,offerApplicable: 'TRUE' ,price: 40},
4:55 PM { first_nom: 'Pirate', last_nom: 'Prentice' ,offerApplicable: 'TRUE' ,price: 50},
4:55 PM { first_nom: 'Lazslo', last_nom: 'Jamf' ,offerApplicable: 'TRUE' ,price: 60 },
4:55 PM { first_nom: 'jitendra', last_nom: 'Prentice' ,offerApplicable: 'TRUE' ,price: 101}
All object with true values are first also sorted with price and then all object having boolean value as false. i am able to sort them by boolean value but i want to sort them by price as well.
i have tried this
var objs = [
{ first_nom: 'Lazslo', last_nom: 'Jamf' ,offerApplicable: 'TRUE' ,price: 60 },
{ first_nom: 'Pig', last_nom: 'Bodine' , offerApplicable: 'FALSE' ,price: 100},
{ first_nom: 'Pirate', last_nom: 'Prentice' ,offerApplicable: 'TRUE' ,price: 50},
{ first_nom: 'nithesh', last_nom: 'Bodine' , offerApplicable: 'FALSE' ,price: 40},
{ first_nom: 'sumeet', last_nom: 'Prentice' ,offerApplicable: 'TRUE' ,price: 40},
{ first_nom: 'mahesh', last_nom: 'Bodine' , offerApplicable: 'FALSE' ,price: 40},
{ first_nom: 'jitendra', last_nom: 'Prentice' ,offerApplicable: 'TRUE' ,price: 101}
];
function compare(a,b) {
var aConcat = a["offerApplicable"] + a["price"];
var bConcat = b["offerApplicable"] + b["price"];
if (aConcat < bConcat )
return 1;
if (aConcat > bConcat )
return -1;
return 0;
}`enter code here`
console.log(objs.sort(compare));
please help thanks in advance.