Reputation: 58831
I have a JS array of objects
const a = [
{name: karl, age: 53},
{name: fred, age: 34},
{name: annie, age: 12},
// ...
];
and I would like to extract the objects with the maximum age
. I could perhaps sort the entire array and just pick the first element, but that seems somewhat wasteful.
Upvotes: 1
Views: 45
Reputation: 239573
You can simply use _.max
, like this
console.log(_.max(a, 'age'));
Upvotes: 4