1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-28 21:32:20 +00:00

docs(string): 增加对于多字节 UTF-16 字符元素展开方法例子

v8 7.2 引擎的 spread 展开运算性能比 for-of 更高
ref: https://v8.js.cn/blog/spread-elements/
This commit is contained in:
waiting 2019-05-25 17:30:16 +08:00
parent dd69d69cc4
commit aebcc496ee
No known key found for this signature in database
GPG Key ID: 9DC706A8664B0312

View File

@ -123,6 +123,16 @@ for (let ch of s) {
// 61 // 61
``` ```
或者使用 `Spread` 展开运算
```javascript
let arr = [...'𠮷a']; // arr.length === 2
arr.forEach(ch => console.log(ch.codePointAt(0).toString(16)));
// 20bb7
// 61
```
`codePointAt()`方法是测试一个字符由两个字节还是由四个字节组成的最简单方法。 `codePointAt()`方法是测试一个字符由两个字节还是由四个字节组成的最简单方法。
```javascript ```javascript