So I have this object like this
{
"value": ["aaa", "bbb", "ccc", "aaa"],
"answer": ["lorem", "lorem", "lorem", "lorem"],
"question": ["lorem", "lorem", "lorem", "lorem"]}
}
How to get word count from property value?
I tried using reduce()
const countedNames = query.reduce((allNames: any, name: any) => {
const currCount = allNames[name.value] ?? 0;
return {
...allNames.value,
[name.value]: currCount + 1,
};
}, {});
but I didn't get the result I'm expecting
The result I'm expecting is something like this
{
"aaa": 2,
"bbb": 1,
"ccc": 1
}