String Split With Unicode

后端 未结 2 993
面向向阳花
面向向阳花 2020-12-16 07:10

First off I been searching the web for this solution.

How to:

<\'\'.split(\'\');

> [\'\',\'\',\'\']

Simply express of

相关标签:
2条回答
  • 2020-12-16 08:00

    for ... of could loop through string contains unicode characters,

    let string = "                                                                    
    0 讨论(0)
  • 2020-12-16 08:02

    As explained in JavaScript has a Unicode problem, in ES6 you can do this quite easily by using the new ... spread operator. This causes the string iterator (another new ES6 feature) to be used internally, and because that iterator is designed to deal with code points rather than UCS-2/UTF-16 code units, it works the way you want:

    console.log([...'                                                                    
    0 讨论(0)
提交回复
热议问题