🔰for-of with strings

JSsyntaxfor loopsfor-of ⟩ with strings

String(s) are iterable.

let freq = {}; 

for(let char of "mississippi") { 
    freq[char] = (freq ?. [char] ?? 0) + 1;
}

freq    // { m: 1, i: 4, s: 4, p: 2 }

Last updated