当前位置:网站首页>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"]
边栏推荐
猜你喜欢
随机推荐
GPS卫星同步时钟,NTP网络同步时钟,北斗时钟服务器(京准)
为什么Redis默认序列化器处理之后的key会带有乱码?
The electromagnetic compatibility EMC protection study notes
附加:自定义注解(参数校验注解);(写的不好,别看…)
什么是 DevOps?看这一篇就够了!
进程间通信方式
云存储硬核技术内幕——小结(上)
快速整明白Redis中的字典到底是个啥
基于 Next.js实现在线Excel
录音文件识别
In action: 10 ways to implement delayed tasks, with code!
【Harmony OS】【FAQ】鸿蒙问题合集2
多商户商城系统功能拆解24讲-平台端分销会员
性能提升400倍丨外汇掉期估值计算优化案例
Projector reached the party benefits 】 【 beginners entry - brightness projection and curtain selection - from entry to the master
邮差"头":{“retCode”:“999999”
实战:10 种实现延迟任务的方法,附代码!
qt 复杂界面信号槽设计
皕杰报表配置文件report_config.xml里都配置了什么?
一文解答DevOps平台的制品库是什么









