I am working with an array of objects and I need to merge all the values of params within each object into a single object.
Array [
Object {
"key": "This week",
"params": Object {
"thisWeekfilterDistance": [Function anonymous],
"thisWeekSearch": [Function anonymous],
"thisWeektoggleFilter": [Function anonymous],
"thisWeektoggleRangeFilter": [Function anonymous],
},
"routeName": "This week",
},
Object {
"key": "Coming soon",
"params": Object {
"soonfilterDistance": [Function anonymous],
"soonSearch": [Function anonymous],
"soontoggleFilter": [Function anonymous],
"soontoggleRangeFilter": [Function anonymous],
},
"routeName": "Coming soon",
},
Object {
"key": "Festivals",
"params": Object {
"festivalfilterDistance": [Function anonymous],
"festivalSearch": [Function anonymous],
"festivaltoggleFilter": [Function anonymous],
"festivaltoggleRangeFilter": [Function anonymous],
},
"routeName": "Festivals",
},
]
I have attempted the following:
for (var i = 0; i < 3; i++) {
if (typeof arr[i].params !== 'undefined') {
//console.log(arr[i].params);
test = arr[i].params;
}
}
or
for (var i = 0; i < 3; i++) {
arr[i].param.reduce(function(result, current) {
return Object.assign(result, current);
}, {})
}
However, I am struggling to figure out how to consolidate these results into a single object containing all object params.
The desired outcome is:
{
"thisWeekfilterDistance": [Function anonymous],
"thisWeekSearch": [Function anonymous],
"thisWeektoggleFilter": [Function anonymous],
"thisWeektoggleRangeFilter": [Function anonymous],
"soonfilterDistance": [Function anonymous],
"soonSearch": [Function anonymous],
"soontoggleFilter": [Function anonymous],
"soontoggleRangeFilter": [Function anonymous],
"festivalfilterDistance": [Function anonymous],
"festivalSearch": [Function anonymous],
"festivaltoggleFilter": [Function anonymous],
"festivaltoggleRangeFilter": [Function anonymous],
}
Thank you.