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; // array element index.
// ⭐ collect "letters" using for-of
for (a[i++] of str) { // ⭐ `lvalue` can be used in for-of.
count += 1;
}
// ⭐ collect "letters" using `str.length`
let b = [];
for (let i = 0; i < 7; i++) {
b[i] = str[i];
}
// ⭐ code points // '❤️' has two code points❗
'❤️'.codePointAt(0), // 10084
'❤️'.codePointAt(1), // 65039
'🐣'.codePointAt(0), // 128035
// ⭐ string length is expected to be 5❗
// neither `.length` nor `for-of` is correnct❗
str.length, // 7❗
count, // 6❗
// (str.length) 7 elements❗
b.map(c => c.codePointAt(0)),
// [73, 32, 10084, 65039, 32, 55357, 56355]
// ╰─── ❤️ ───╯ ╰─── 🐣 ───╯
// └── surrogate pair ?
// (for-of) 6 elements❗
a,
// [ 'I', ' ', '❤', '️', ' ', '🐣' ]
// ╰──❤️──╯
a.map(c => c.codePointAt(0)),
// [ 73, 32, 10084, 65039, 32, 128035 ]
// ╰─── ❤️ ───╯ ╰─🐣─╯
String.fromCodePoint(10084), // '❤'