[SOLVED] Escaping emojis in javascript | Sololearn: Learn to code for FREE!


[SOLVED] Escaping emojis in javascript

How to escape emoji characters in javascript? Eg: 😝 => 😝 😞 => 😞 But my code makes 2 characters, 😝 => �� Which is invalid code? What is the correct way. Any ideas? https://code.sololearn.com/WtVy7RukBe2h/?ref=app

12/18/2020 10:25:29 AM

Bibek Oli

6 Answers

New Answer


It ignores the newline because of your regex pattern. Dot (.) does not match newlines. Here is a fixed version (see line 5) https://code.sololearn.com/W2ej6jz9ngia/?ref=app


This will hopefully help (sorry if it doesn't because I haven't read the full article) https://medium.com/reactnative/emojis-in-javascript-f693d0eb79fb


March Zucherberg apparently, "😝".codePointAt(0) returns 128541. So the example you mentioned in the question is actually the code point at position 0. And it can be easily converted to the emoji. Using String.fromCodePoint() on the hex equivalent of the code point at position 0 of the emoji returns the emoji itself. See if this helps https://code.sololearn.com/Wuah65dHU7pO/?ref=app


After some research on your code and more on the post you provided a link on your code, I finally got what I needed. But still unknown if this method is still efficient. Please have a look at it.. https://code.sololearn.com/WV3mUti1hj39/?ref=app


But I found 1 problem in it i.e. it doesn't escape newlines to => 
 Totally ignores it.


XXX thanks, but I didn't understand anything, full of regex. So, I did some more research and found another way, It gives the correct emoji character code but also one more code at the end. https://code.sololearn.com/W5c3br0qEyQJ/?ref=app &#56...; These codes.