I want to return the key of the first object returned by the _.orderBy()
method which sorts by a nested property.
Here is the CodePen demo. In this case, the key I want to return is "charlie"
.
console.clear();
const ob = {
"alpha": {
"id": 27,
"lottery": {
"id": 1,
"name": "La Primitiva",
"jackpotAmount": 500,
}
},
"bravo": {
"id": 28,
"lottery": {
"id": 1,
"name": "La Primitiva",
"jackpotAmount": 10,
}
},
"charlie": {
"id": 29,
"lottery": {
"id": 1,
"name": "La Primitiva",
"jackpotAmount": 1000,
}
},
}
const out = _.orderBy(ob, (e) => {
return e.lottery.jackpotAmount;
}, ['desc'] ); // How do I get key of first property, "charlie"?
console.log(out);