DEV Community

Nagarajan R
Nagarajan R

Posted on

Answer: Group objects by property in javascript

Assuming the original list is contained in a variable named list:

_
.chain(list)
.groupBy('type')
.map(function(value, key) {
    return {
        type: key,
        foods: _.pluck(value, 'food')
    }
})
.value();

Top comments (0)