How do you convert a multi-dimensional array into an array of objects using .reduce()?
Starting array
[
[
['juice', 'apple'], ['maker', 'motts'], ['price', 12]
],
[
['juice', 'orange'], ['maker', 'sunkist'], ['price', 11]
]
]
And ending array
[
{juice: 'apple', maker: 'motts', price: 12},
{juice: 'orange', maker: 'sunkist', price: 11}
]
This is what I have now. This is really just me shooting in the dark.
var transformData = (array) => {
var newArray = array.push(function (all, item, index) {
var newItem = item.reduce(function (all, item, index) {
all[item[0]] = item[1]
return all
}, {})
return all
}, [])
newArray.push(newItem)
return newArray
}
array.mapinstead of ` array.push(`