say I have a data structure that looks like this:
data = [
{title: "Alpha", content: [{ // 1 item }]},
{title: "Beta", content: [{ // 10 items }]},
{title: "Beta", content: [{ // 12 items }]},
{title: "Beta", content: [{ // 8 items }]}
]
I'd like to figure out a reduce function that would return the following structure:
data = [
{title: "Alpha", content: [{ // 1 item }]},
{title: "Beta", content: [{ // 30 items }]}
]
I've tried looking at some answers where reduce is used based on title but it did not return the new structure with the accumulated content array such as:
data = data.reduce((x, e) => {
x.push(
Object.assign(
{},
e,
messages.find((x) => x.title == e.title)
)
)
return x
}, [])
Any help would be great.