Split Chinese Characters
How can I split foreign characters, such as Chinese, into separate array values using JavaScript? split() seems to work well with English, but not so much with Chinese. See below
Solution 1:
There is no way to do that reliably using built-in ES5 facilities without using any 3rd party libraries.
The correct way using vanilla JS is to use ES2015 spread operator:
let splitString = [...text];
Examples of strings which would cause the split
-based solutions to fail: 𠀁
Solution 2:
Instead of splitting on a space char (which there aren't any in the chinese string), try splitting on an empty string "", which should split each char into its own element.
Post a Comment for "Split Chinese Characters"