Split string to array
Then count
let arr = [..."⛔"] // ["", "", "", "⛔", "", "", ""]
let len = arr.lenght
Credit to downGoat
Note that this solution won't work in some special cases, such as commented below were one smiley is composed by four: [...""] -> ['', '', '', '', '', '', '']
Though I posted it here for Google searches as for most cases it works, and it is much easier then all other alternatives.
Full solution
To overcome special emojis as the one above, one can search for the connection charecter and make some modifications.
The char code for this is 8205 (UTF-16).
Here is how to do it:
let myStr = ""
let arr = [...myStr]
for (i = arr.length-1; i--; i>= 0){
if (arr[i].charCodeAt(0) == 8205) { // find & handle special combination character
arr[i-1] += arr[i] + arr[i+1];
arr.splice(i, 2)
}
}
console.log(arr.length) //2
Haven't found a case where this doesn't work. Comment if you do