I\'m trying to iterate through an array of digits and count how many times each digit is found in the array.
In ruby it\'s easy, I just declare a Hash.new(0)
Hash.new(0)
You can use Map,
Map
hash
1
let arr = [1, 0, 0, 0, 1, 0, 0, 1] let hash = new Map() arr.forEach(val => { hash.set(val, (hash.get(val) || 0) + 1) }) console.log([...hash])