Instead of using:
You should be using:
In practice, the trick here is to know that most methods like
'hello'.split('') specifically count UTF-16 code units, rather than code points. A dry distinction really, but an important one. By rote memory, you should know that ES6's
Array.from method correctly chunks characters like emojis together.
ASIDE: Jump down the Unicode rabbit hole and checkout Awesome Unicode, a really comprehensive, and surprisingly exciting, guide on Unicode.
Here's how it all works out.
const str = 'taco 🐛 cat'; str.split('').reverse().join(''); :> "tac �� ocat" Array.from(str).reverse().join(''); :> "tac 🐛 ocat"