I have this array, that contains more arrays with objects inside that contains information about words founded in pages. Here one example:
let data = [
[],
[{
"word": "society",
"count": 5,
"pageIndex": 1
},
{
"word": "identity",
"count": 2,
"pageIndex": 1
}
],
[{
"word": "society",
"count": 2,
"pageIndex": 2
},
{
"word": "identity",
"count": 2,
"pageIndex": 2
}
],
[{
"word": "society",
"count": 2,
"pageIndex": 3
},
{
"word": "identity",
"count": 1,
"pageIndex": 3
}
],
[],
[],
[{
"word": "society",
"count": 1,
"pageIndex": 6
}],
[],
[{
"word": "society",
"count": 1,
"pageIndex": 8
}],
[{
"word": "society",
"count": 1,
"pageIndex": 9
}]
]
What I want is to build a final array of objects with this structure to join the information of each word founded in just one object
const final = [{
"word": "society",
"countFinal": 12,
"pagesIndexes": [1, 2, 3, 6, 8, 9]
},
{
"word": "identity",
"countFinal": 5,
"pagesIndexes": [1, 2, 3]
}
]
Any ideas on how to achieve this in JS?