Former un objet avec réduction
const FRUITS = ["banana", "apple", "orange", "banana", "orange",
"apple", "apple", "orange", "orange", "banana", "orange", "banana"];
const total = FRUITS.reduce((map, fruit) => ({
...map,
[fruit]: (map[fruit] || 0) + 1,
}), {});
console.log(total); // { banana: 4, apple: 3, orange: 5}
Clever Caterpillar