How to get count of duplicate items in array in JavaScript

Arrays
By Jad Joubran · 
Last updated Jan 08, 2018
const chars = ["a", "b", "c", "a", "a", "c"];
let result = {};

result = chars.reduce((acc, item) => {
  acc[item] = acc[item] ? ++acc[item] : 1;
  return acc;
}, result);
{
    a: 3,
    b: 1,
    c: 2
}