Last updated 2 years ago
Was this helpful?
JS⟩ syntax ⟩ for loops ⟩ for-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 }
iterable
for-of with objects
for-in
related concepts used in examples
replit: for-of with strings
Note:in the following code, '❤' is actually '❤️', except line 40, 46❗
// ⭐ string with emojis. const str = 'I ❤️ 🐣'; let count = 0; // count "characters" with for-of loop. let a = []; // store "characters" in an array. let i = 0
JavaScript: The Definitive Guide ⟩ 5.4.4 for/of loop
Unicode Table ⟩ U+FE0F (65039)
for...of
Object ⟩
Object.keys()
Object.prototype ⟩
How to get the Unicode code point for a character in Javascript?
Why '❌'[0] === '❌' but '✔️'[0] !== '✔️'?