let arr = [ '3', '3', '6' ] let result = {}; arr.forEach((v) => { result[v] = (result[v] || 0) + 1; }); console.log(result); // { '3': 2, '6': 1 }