I have this array:
const obj = [
{
value: 1,
position: 1,
id: 333,
},
{
value: 1,
position: 2,
id: 222,
},
];
I'm using maxBy from lodash to get the max value of the attribute called value.
_.maxBy(obj, "value");
So, the problem is that there are two objects with the same value attribute and the maxBy is showing me the last object. In this case, I would need to make the maxBy and the same time, referring the less value to the position attribute.
Any help ?
_.maxBy
acceptsiteratee
as second params, we can custom theiteratee
. Your current way is using the_.property
iteratee shorthand.The solution for your case: