Which fix handles the text correctly?
const first = 'e\u0301'.charAt(0);
console.log('🙂'.length);
- Iterate code points:
[...str]instead - Iterate code points:
str.split('')instead - Call
normalize()after taking charAt - Compare with
charCodeAt(0)instead
length and charAt count UTF-16 units, so an emoji counts as 2; spreading walks code points.
Play Problem Solving ▸