How to count EMOJI in a string or text line and display the output, how many emoji are in the text line or string?
For example:
One option would be to compare the length of the input string against the length of the same string with all Emoji characters removed:
function fancyCount(str){
return Array.from(str.split(/[\ufe00-\ufe0f]/).join("")).length;
}
var input = "Hello
The accepted answer does not work in every case, such as the ❤️
emoji which is counted as 0
and some emojis are counted as more than '1' like the
You can try this lib https://github.com/mathiasbynens/emoji-regex It provides emojiRegex. So you can match emojis in your test like this:
const text = "Hello
You can check the char code for the emojis and count them that way.