I have two arrays. my Array1 is a multi-dimensional array of just strings.
The Array2 is an array of objects. each object has 2 key value pairs one is called “value” the other is “HeaderIndex”
If Array1 has an array with a string a index 0 I want to find the “value” key from Array2 and convert the Array1 string to a new object matching the HeaderIndex value.
I am trying to convert the multi dimensional array to another multidimensional array but instead of strings, I want it to be objects depending on index prop from Array2
const Array1 = [
['Alex', 'Boe', 'MeowWolf', 'pizza', 'pink'],
['Arron', 'Coe', 'Kmart', 'tofu', 'purple'],
['Jane', 'Doe', 'Sears', 'tacos', 'orange'],
['John', 'Eoe', 'YugiOh', 'blueberries', 'magenta'],
['Suzie', 'Boe', 'Toyota', 'steroids', 'blue']
]
const Array2 = [
{ value: 'First name', HeaderIndex: 0},
{ value: 'Last name', HeaderIndex: 1},
{ value: 'Company', HeaderIndex: 2},
{ value: 'Favorite food', HeaderIndex: 3},
{ value: 'Favorite color', HeaderIndex: 4},
]
I am trying to get this output below
const Finalresult = [
[{First name: 'Alex'}, {Last name: 'Boe'}, {company: 'MeowWolf', {Favorite food: "pizza", {Favorite color: "pink"}],
[{First name: 'Arron'}, {Last name: 'Boe'}, {company: 'Kmart', {Favorite food: "tofu", {Favorite color: "purple"}],
[{First name: 'Jane'}, {Last name: 'Doe'}, {company: 'Sears', {Favorite food: "tacos", {Favorite color: "orange"}],
[{First name: 'John'}, {Last name: 'Eoe'}, {company: 'YugiOh', {Favorite food: "blueberries", {Favorite color: "magenta"}],
]