Reputation: 972
From twitter feed I am getting below code. How to convert this twitter unicode to emoji in javascript?
(&# 128079;&# 128079;&# 128079;&# 128079;)
to
👏👏👏👏
How to show the emoji symobol using javascript?
Upvotes: 0
Views: 196
Reputation: 35263
You could use the regex /&# (\w+);/
to get each Code point to a capturing group. Then use String.fromCodePoint
method in the replacement function of replace
to get the emojis like this:
const str = '&# 128079;&# 128079;&# 128079;&# 128079;'
const emojiStr = str.replace(/&# (\w+);/g, (m, c1) => String.fromCodePoint(c1))
console.log(emojiStr)
If you just want to display it on the DOM, you can just remove the space (\s
) and set the escaped string to innerHTML
const str = '&# 128079;&# 128079;&# 128079;&# 128079;'
document.getElementById('display').innerHTML += str.replace(/\s/g, '')
<span id='display'></span>
Upvotes: 2