I have this data in my CartData usestate hook.
[
0:[
0:{
data1: "any",
data2: "any",
imgArray: ["img1.jpg"],
},
1:{
data1: "any",
data2: "any",
imgArray: ["img2.jpg"],
}
]
]
And I want to store imgArray data i.e ( img1.jpg & img2.jpg ) in a nested array like shown below. Because in future each array on each index can have multiple items.
imageArray: [ 0: ["img1.jpg"], 1: ["img2.jpg"] ]
I'm using this code below. But not getting desired output. How can I do that?
let imageArray = [], data1 = [], data2 = [];
CartData.map((value, index) => {
value.map((value, index) => {
value.imgArray.map((value, index) => {
imageArray[index]=value;
})
data1[index] = value.data1;
data2[index] = value.data2;
})
}
Getting following Output using above code.
{
data1 : [ 0: "any", 1: "any"],
data2 : [ 0: "any", 1: "any"],
imageArray : [ 0: "img1.jpg"],
}
I also tried this in map but not got the desired result.
imageArray[index[index]] = value;