Last Updated: February 25, 2016
·
4.866K
· ejstembler

Grouping by multiple fields in JavaScript or CoffeeScript using Underscore

https://gist.github.com/3914319

gistfile1.coffee

# Group by field1 and field2
 groupedData = _.groupBy(data, (d) ->
   "#{d.field1}-#{d.field2}"
 )

groupby.js

// Group by field1 and field2
 var groupedData = _.groupBy(data, function(d) {
    return d.field1 + "-" + d.field2;
 });