JavaScript: Iterate String
Enumerate Chars in String via For-Of Loop
Best way to go thru each char in string is using for-of Loop.
for (let x of "aπc") { console.log(x); } // a // π // c
Convert String to Array
Another way is to convert string to array, then use any array methods to go thru.
[..."aπc"].forEach( ((x) => { console.log(x); }) ); // prints // a // π // c
Using For-Loop (go thru 16-bits units)
If string contains emoji or rare Unicode character, for-loop behaves in unexpected way. (for why, see [see JavaScript: String Code Unit] )
const str = "aπc"; for (let i = 0; i < str.length; i++) { console.log(str[i]); } // prints // a // οΏ½ // οΏ½ // c