So currently I have this array structure:
const object = {
object1: ["01", "02"],
object2: ["item1", "item2", "item3"],
object3: ["product1", "product2"]
}
and I need to transform it to:
const array = [
{
object1: "01",
object2: "item1",
object3: "product1",
}, {
object1: "02",
object2: "item1",
object3: "product1",
}, {
object1: "01",
object2: "item2",
object3: "product1",
}, {
object1: "01",
object2: "item3",
object3: "product1",
}, {
object1: "02",
object2: "item2",
object3: "product1",
}, {
object1: "02",
object2: "item3",
object3: "product1",
}, {
object1: "01",
object2: "item1",
object3: "product2",
}, {
object1: "02",
object2: "item1",
object3: "product2",
}, {
object1: "02",
object2: "item2",
object3: "product2",
}, {
object1: "03",
object2: "item2",
object3: "product2",
},
]
So basically I need to create a new array based off of each combination on the initial object of arrays, and the initial array the be on the thousands of items.
This is what I have so far but no luck getting the structure I need.
const object = {
object1: ["01", "02"],
object2: ["item1", "item2", "item3"],
object3: ["product1", "product2"]
}
const arr = []
Object.entries(object).forEach((element, i) => {
element.forEach((innerElement, j) => {
let _element = {[`${element[0]}`]:element[1][j]}
arr.push(_element)
})
});
console.log("map", arr)
Is there any way to transform the data to the structure I need it? Thanks in advance!