Skip to content

Commit 424d5e4

Browse files
authored
Merge pull request ruanyf#859 from waitingsong/string-methods
docs(string): 增加对于多字节 UTF-16 字符元素展开方法例子
2 parents fe02a92 + aebcc49 commit 424d5e4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docs/string-methods.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ for (let ch of s) {
123123
// 61
124124
```
125125

126+
或者使用 `Spread` 展开运算
127+
128+
```javascript
129+
let arr = [...'𠮷a']; // arr.length === 2
130+
arr.forEach(ch => console.log(ch.codePointAt(0).toString(16)));
131+
// 20bb7
132+
// 61
133+
```
134+
135+
126136
`codePointAt()`方法是测试一个字符由两个字节还是由四个字节组成的最简单方法。
127137

128138
```javascript

0 commit comments

Comments
 (0)