I have array of array like
{
"campaigns": [{
"name": "1st Campaign",
"books": [{
"title": "1st book",
"primary_isbn": "isbn1"
},
{
"title": "2nd book",
"primary_isbn": "isbn2"
},
{
"title": "3rd book",
"primary_isbn": "isbn3"
}
]
},
{
"name": "2nd cam",
"books": [{
"title": "4th book",
"primary_isbn": "isbn4"
},
{
"title": "5th book",
"primary_isbn": "isbn5"
}
]
}
]
}
From above array i need to create new array where each campaign (parent) data converted to number of items per book. So for first item 1st campaign should be converted to 3 items as there are 3 books. so my new array should be
{
"campaigns": [{
"name": "1st campaign"
"title": "1st book",
"primary_isbn": "isbn1"
},
{
"name": "1st campaign"
"title": "2nd book",
"primary_isbn": "isbn2"
},
{
"name": "1st campaign"
"title": "3rd book",
"primary_isbn": "isbn3"
},
...
]
}
And same structure for 2nd campaign. I am not sure how to approach this problem
I tried this using lodash
_.flattenDeep(data.campaigns.books)
"1st book","2nd book"in the output come from? Or should that be computed based on the index? Why isprimary_isbndifferent from the input?