So I have this array
var mapped = [[2016, "October", "Monday", {object}], [2017, "January", "Friday", {object}], [2017, "January", "Wednesday", {object}], [2017, "October", "Monday", {object}]]
What I want to accomplish is something like this:
[{
"2016": [{
"October": [{
"Monday": [{object}]
}]
}],
}, {
"2017": [{
"January": [{
"Friday": [{object}]
}, {
"Wednesday": [{object}]
}]
}, {
"October": [{
"Monday": [{object}]
}]
}]
}]
I've been searching around for so long, and I can't find a solution.. By using reduce, I'm getting something like this:
[
2016: [{
"month": "October"
}]
],
[
2017: [{
"month": "January"
},
{
"month": "January"
},
{
"month": "September"
}]
]
So it seems like I'm into something, but still so far away... This is what I'm doing:
mapped.reduce((years, array) => {
years[array[0]] = years[array[0]] || [];
years[array[0]].push({
month: array[1]
})
return years;
}, [])