Splitting Strings

In Javascript, if you split a string by characters using the split method, you'll get an array of characters. For example:

const str = 'hello';
const arr = str.split('');
console.log(arr); // ['h', 'e', 'l', 'l', 'o']

But if the string contains emojis, and since emojis are typically represented using two characters in JavaScript, you'll get an array of individual characters, which may not be what you want. So, to split a string by characters, including emojis, you can use the spread operator:

const str = 'surrogate pairs 🫃'
const arr = [...str];
console.log(arr); // ['s', 'u', 'r', 'r', 'o', 'g', 'a', 't', 'e', ' ', 'p', 'a', 'i', 'r', 's', ' ', '🫃']