I've got an RESTful call that's returning data that resembles the following:
[{
name: "one",
dayID: "Tuesday},
{
name: "two",
dayID: "Monday"
},
{
name: 'three'
dayID: "Tuesday
}]
What I'm trying to do is iterate over the data and create a new array that has a nested structure based on a unique attribute. So if the array already has a Monday, push the json to that object. If not, make a new one. In this case nesting all objects under the day, so the new array would look like this:
[{"Monday":["two"]}, {"Tuesday":["one", "three"]}]
These won't be strings in practice, they'll be additional objects but for the sake of simplicity I'm asking for strings in my example. Any help is appreciated.
Array.reduce-> jsfiddle.net/thgvvm05