Bit of background, this comes from a submitted form that I used serializeArray() on I have a list of objects like so.
[
{name: 0, value: 'waffles'},
{name: 0, value: 'pancakes'},
{name: 0, value: 'french toast'},
{name: 1, value: 'pancakes'}
]
I want to take all things that have the same name attribute and put them together. EG,
[
{name: 0, value: ['waffles', 'pancakes', 'french toast']},
{name: 1, value: ['pancakes']}
]
how would one go about this? All the things I've tried only result in one answer being shown for each name key.
I am one of those guys that uses native functions:
This should do it:
I'd probably do something like this:
Using
_.chain
and_.value
makes things flow nicely and using named functions make things less messy and clarifies the logic.Demo: http://jsfiddle.net/ambiguous/G7qwM/2/
This seems to work:
Demonstration
Here's the best I could come up with:
http://jsfiddle.net/Z6bdB/