(You'll need Firefox or Safari to see the emoji in the code.)
I want to take a string of emoji and do something with the individual characters.
In JavaScript "😴😄😃⛔🎠🚓🚇".length == 13
because "â›”"
length is 1, the rest are 2. So we can't do
var string = "😴😄😃⛔🎠🚓🚇"; s = string.split(""); c = []; c[0] = s[0]+s[1]; console.log(c);
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
Description. In JavaScript, split() is a string method that is used to split a string into an array of strings using a specified delimiter. Because the split() method is a method of the String object, it must be invoked through a particular instance of the String class.
The <br> HTML element produces a line break in text (carriage-return). It is useful for writing a poem or an address, where the division of lines is significant.
JavaScript ES6 has a solution!, for a real split:
[..."😴😄😃⛔🎠🚓🚇"] // ["😴", "😄", "😃", "⛔", "🎠", "🚓", "🚇"]
Yay? Except for the fact that when you run this through your transpiler, it might not work (see @brainkim's comment). It only works when natively run on an ES6-compliant browser. Luckily this encompasses most browsers (Safari, Chrome, FF), but if you're looking for high browser compatibility this is not the solution for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With