const listItems = ["papa", "camote", "yuca", "papa"];
const result = listItems.reduce((acc,current: string) => {
acc[current] = acc[current] ? acc[current] + 1 : 1;
return acc;
}, {} as any);
console.log(result);
example response:
[LOG]: {
"papa": 2,
"camote": 1,
"yuca": 1
}
Top comments (0)