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;
});Written by Edward J. Stembler
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Underscore.js
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#