String length counts UTF-16 units. A for-of loop advances by Unicode code point, which keeps a supplementary character together.
Worked example
for (const char of "A๐") console.log(char);Result
A
๐Implementation notes
A cursor that advances one code point at a time can still land inside a visible character. For editing selections, compare the result with a grapheme-aware segmenter.
Try it yourself
Compare an emoji with a family emoji. The second still contains several code points.
Open the JavaScript example โEditorial date September 16, 2026 ยท Published December 6, 2026