Today Wes Bos tweeted a few fun things one can do with JavaScript and Emoji:
-
It’s possible to spread emoji sequences into their single parts:
[...'๐จโ๐ฉโ๐งโ๐ฆ'] // ["๐จ", "โ", "๐ฉ", "โ", "๐ง", "โ", "๐ฆ"]
-
Combining Emoji is also possible:
["๐จ", "โ", "๐ฉ", "โ", "๐ง"].reduce((prev, curr) => prev + curr) // "๐จโ๐ฉโ๐ง"
-
And oh, you can even replace single emoji within emoji units, yielding a new emoji unit:
'๐ฉโ๐ฉโ๐ฆ'.replace(/๐ฉ/g, '๐จ') // "๐จโ๐จโ๐ฆ"
-
This kind of sorcery also works with skin tone modifiers by the way:
[...'๐๐พ'] // ["๐", "๐พ"] ["๐", "๐พ"].reduce((prev, curr) => prev + curr) // "๐๐พ" '๐๐พ'.replace("๐พ", "") // "๐"
Digging deeper into this it came to my attention that the extra character in between the single emoji after splitting (see example 1) is not an empty string but a zero-width joiner (ZWJ
). The ZWJ
("\u200d"
) acts as the glue between the single emoji, yielding the correct combined emoji sequence.
The full list of Emoji ZWJ Sequences contains all possible sequences, and holds some (toe me) nice surprises. Take the rainbow flag emoji (๐ณ๏ธโ๐) for example: that actually is a combination of a white flag emoji and a rainbow emoji!
'๐ณ' + '\u200d' + '๐'
// "๐ณ๏ธโ๐"
Geekfun! ๐ค
Consider donating.
I don’t run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!
Leave a comment