I'd appreciate some help in this problem I'm trying to solve in a particular way. I'm trying to use forEach() and reduce() to transform a dataset from one format - an array of arrays - into another - an array of objects. I know that arr.forEach(i) => {...} will access each item in the array then I can use arr.reduce(acc, curr) => {...} to transform the nested arrays and its values into an object I'm having a hard time visualizing and reasoning out how to use .reduce() in the nested array to access and thus assign the key-value pairs in the object. Thanks in advance for your help and explanations.
Here's the raw data:
const theData = [
[
["productName", "The Product"],
["productOrigin", "Some Country"],
["productNumber", 100],
["comment", "Some Comment"]
],
[
["productName", "Another Product"],
["productOrigin", "Some other Country"],
["productNumber", 45],
["comment", "some comment"]
]
]
The output I'm shooting for is this:
const formattedData = [
{
productName: "The Product",
productOrigin: "Some Country",
productNumber: 100,
comment: "Some Comment
},
productName: "Another Product",
productOrigin: "Some other Country",
productNumber: 45,
comment: "Some Comment"
}
]