Suppose I have an array of array and an empty array:
const sampleArray = [ [{"book":["harry pottar","lotr"]},{"book":["omega","beta"]}] ,
[{"book":["ronjan","pirates","simba"]},{"book":["musical","eskobar","elsa"]}],
[{"book":["book1","book2","book3"]},{"book":["book4","book5"]}] ]
const emptyArray = []
What I want is to push the total length of book of first element of array as one, second element of array as one, third as one and so on. Such that O/P looks like:
console.log(emptyArray) => [4,6,5] => total length of book for each element of array.
For this, I tried as,
for(let i =0; i<sampleArray.length;i++){
for(let j = 0; j<sampleArray[i].length;j++){
emptyArray.push(sampleArray[i][j].book.length)
}
}
But it just pushes length for each books as: [2,2,3,3,3,2].
I'm unable to get to the logic where I can merge two book's array into one.
If anyone needs any further information please do let me know.