The purpose of _.pluck
is to retrieve a field for each object in a collection - since _.max
returns only a single object, you don't need to pluck, you can simply retrieve the field from the one object you have:
var maxScore = _.max(peopleList, scoreLabel)[scoreLabel];
The above will retrieve the person from peopleList
who has the largest scoreLabel
, and then retrieve that person's scoreLabel
value.
Alternatively, you could swap the order of the calls to _.max
and _.pluck
, like this:
var maxScore = _.max(_.pluck(peopleList, scoreLabel));
This will build a collection of all the scoreLabel
values, and then retrieve the largest one.