Let’s say I have this 3 emojis in a string: 😀🎃👪
There are not any spaces or any other character except emojis in the string.
How can I remove the last emoji in javascript?
Advertisement
Answer
Ok, here is how I solved it:
function deleteEmoji(emojiStr) { let emojisArray = emojiStr.match(/([uD800-uDBFF][uDC00-uDFFF])/g); emojisArray = emojisArray.splice(0, emojisArray.length - 1); return emojisArray.join(""); } let emojitext = "😀🎃👪"; console.log(deleteEmoji(emojitext));