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();
Related Contents:
- Most efficient method to groupby on an array of objects
- JavaScript merging objects by id
- Underscore template throwing variable not defined error
- Find by key deep in a nested array
- Explanation of …
- Add property to an array of objects
- How to use underscore.js as a template engine?
- One liner to flatten nested object
- using underscore’s “difference” method on arrays of objects
- External template in Underscore
- using lodash .groupBy. how to add your own keys for grouped output?
- Comparing two arrays of objects, and exclude the elements who match values into new array in JS
- Convert array of strings into an array of objects
- Loading Backbone and Underscore using RequireJS
- Removing duplicate objects with Underscore for Javascript
- Split JavaScript array in chunks using Lodash
- Javascript group objects by property [closed]
- break array of objects into separate arrays based on a property
- Underscore: sortBy() based on multiple attributes
- How to use if statements in underscore.js templates?
- What does _.debounce do?
- how to break the _.each function in underscore.js
- Recursive/deep extend/assign in Underscore.js?
- What is context in _.each(list, iterator, [context])?
- How to use underscore’s “intersection” on objects?
- correctly implement backbone comparators
- Use underscore inside Angular controllers
- Convert returned JSON Object Properties to (lower first) camelCase
- ESLint’s “no-undef” rule is calling my use of Underscore an undefined variable
- Update if exists or add new element to array of objects – elegant way in javascript + lodash
- Return an object key only if value is true
- Remove duplicates in an object array Javascript
- What is JavaScript garbage collection?
- AngularJS : Difference between the $observe and $watch methods
- How to remove all listeners in an element? [duplicate]
- Remove insignificant trailing zeros from a number?
- How to create a session using JavaScript?
- How can I determine the current line number in JavaScript?
- Trim spaces from start and end of string
- What’s the difference between a continuation and a callback?
- A good way to redirect with a POST request?
- How can I use JavaScript on the client side to detect if the page was encrypted?
- Scraping data to google sheets from a website that uses JavaScript
- D3js – change Vertical bar chart to Horizontal bar chart
- Array.size() vs Array.length
- infinite-scroll jquery plugin
- Javascript, viewing [object HTMLInputElement]
- How to include scripts automatically in a yeoman/grunt project?
- How can I differentiate between an arrow function, class and a normal function?
- Uncaught Error: Cannot find module ‘jquery’