Underscore.js find unique values in array of objects; Return unique items and their count

A nice solution is to use the optional iterator function to underscore's uniq function:

let people = [
  {name: "Alice", age: 21}, 
  {name: "Bob", age: 34},
  {name: "Caroline", age: 21}
];
_.uniq(people, person => person.age);

Docs: http://underscorejs.org/#uniq


I think you're looking for the countBy function:

_UNIQUEAGEARRAY = _.countBy(_PERSONARRAY, "age");

It produces the result:

{"2":1,"7":2,"9":1}

JSFiddle demo: http://jsfiddle.net/4J2SX/