当前位置:网站首页>5 基本引用类型
5 基本引用类型
2022-08-04 15:38:00 【你回到了你的家】
3 原始值包装类型
3.3 String
3.3.9 字符迭代与解构
待补充 @@iterator是什么
字符串的原型上暴露了一个@@iterator 方法,表示可以迭代字符串的每个字符。可以像下面这样手动使用迭代器:
let message = "abc";
let stringIterator = message[Symbol.iterator]();
console.log(stringIterator.next()); // {value: "a", done: false}
console.log(stringIterator.next()); // {value: "b", done: false}
console.log(stringIterator.next()); // {value: "c", done: false}
console.log(stringIterator.next()); // {value: undefined, done: true}
在 for-of 循环中可以通过这个迭代器按序访问每个字符:
for (const c of "abcde") {
console.log(c);
}
// a
// b
// c
// d
// e
有了这个迭代器之后,字符串就可以通过解构操作符来解构了。比如,可以更方便地把字符串分割为字符数组:
let message = "abcde";
console.log([...message]); // ["a", "b", "c", "d", "e"]
边栏推荐
- Beginner crawler notes (collecting data)
- Online Excel based on Next.js
- 不需要服务器,教你仅用30行代码搞定实时健康码识别
- What is the difference between ITSM software and a work order system?
- 游戏网络 UDP+FEC+KCP
- 视频字幕API接口文档
- An article to answer what is the product library of the DevOps platform
- 多线程编程之优先级翻转问题
- Xi'an Zongheng Information × JNPF: Adapt to the characteristics of Chinese enterprises, fully integrate the cost management and control system
- 卖家寄卖流程梳理
猜你喜欢
随机推荐
游戏网络 UDP+FEC+KCP
我在羊毛和二手群里报复性消费
What is an artifact library in a DevOps platform?What's the use?
无心剑七绝《七夕牵手》
Redis-哨兵模式
弄懂#if #ifdef #if defined
图解 SQL,这也太形象了吧!
H5 开发内嵌页面跨域问题
Go 言 Go 语,一文看懂 Go 语言文件操作
A detailed explanation of what is software deployment
吴恩达机器学习[9]-神经网络学习
inter-process communication
有哪些好用的IT资产管理平台?
For循环控制
MySQL当前读、快照读、MVCC
为什么Redis默认序列化器处理之后的key会带有乱码?
AIX7.1安装Oracle11g补丁33829709(PSU+OJVM)
一文解答DevOps平台的制品库是什么
365天挑战LeetCode1000题——Day 049 非递增顺序的最小子序列 贪心
ICDE‘22推荐系统论文之Research篇








![吴恩达机器学习[11]-机器学习性能评估、机器学习诊断](/img/99/179c4c2db2b6c1edb61f129d46f313.png)
