From aebcc496eefb0b4880b0d7b2caa1da0cec30d9c2 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Sat, 25 May 2019 17:30:16 +0800 Subject: [PATCH] =?UTF-8?q?docs(string):=20=E5=A2=9E=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E4=BA=8E=E5=A4=9A=E5=AD=97=E8=8A=82=20UTF-16=20=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E5=85=83=E7=B4=A0=E5=B1=95=E5=BC=80=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BE=8B=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v8 7.2 引擎的 spread 展开运算性能比 for-of 更高 ref: https://v8.js.cn/blog/spread-elements/ --- docs/string-methods.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/string-methods.md b/docs/string-methods.md index 07b2938..0d5f4cd 100644 --- a/docs/string-methods.md +++ b/docs/string-methods.md @@ -123,6 +123,16 @@ for (let ch of s) { // 61 ``` +或者使用 `Spread` 展开运算 + +```javascript +let arr = [...'𠮷a']; // arr.length === 2 +arr.forEach(ch => console.log(ch.codePointAt(0).toString(16))); +// 20bb7 +// 61 +``` + + `codePointAt()`方法是测试一个字符由两个字节还是由四个字节组成的最简单方法。 ```javascript