学习笔记:ES6之Iterator接口和for…of循环
来源:互联网 发布:矩阵的几为3和秩的关系 编辑:程序博客网 时间:2024/06/05 00:55
(1)什么是Iterator接口
(2)Iterator的基本用法
letarr=['hello','world'];
letmap=arr[Symbol.iterator]();
console.log(map.next());
console.log(map.next());
console.log(map.next());
(2)部署接口:有颜色字体标志的是必须要有的(重要)
letobj={
start:[1,3,2],
end:[7,9,8],
[Symbol.iterator](){
letself=this;
letindex=0;
letarr=self.start.concat(self.end);
letlen=arr.length;
return{
next(){
if(index<len){
return{
value:arr[index++],
done:false
}
}else{
return{
value:arr[index++],
done:true
}
}
}
}
}
};
for(letkeyofobj){
console.log(key);//1 3 2 7 9 8
}
for… of
letarr=['hello','world'];
for(letvalueofarr){
console.log(value);//hello world
}
阅读全文
0 0
- 学习笔记:ES6之Iterator接口和for…of循环
- ES6学习笔记之Iterator和for...of循环
- ES6学习笔记(七)Iterator和for...of循环
- 5、Iterator和for...of循环—ES6学习笔记
- ES6系列之---Iterator和for...of循环
- ES6--Iterator和for...of循环
- es6 iterator和for...of循环
- ES6--iterator和for-of循环
- es6的iterator和for of循环
- ES6之Iterator和for...of
- ECMAScript 6 学习笔记----Iterator和for...of循环
- ES6入门——Iterator和for...of循环
- 自学-ES6篇-Iterator和for...of循环
- es6 javascript的Iterator 和 for...of 循环
- ES6(二) Iterator(遍历器)和for-of循环
- ES6之Iterator和for...of循环(只用于自己回顾)
- 【es6】Iterator 和 for...of
- ECMAScript6笔记:Iterator和for...of循环
- String的trim方法
- Android_ToolBar基础
- Java poi操作合并单元格后写入内容
- SQL Server还原数据库方法总结
- Spring Boot -- 微信企业号开发04-AesException非法字符
- 学习笔记:ES6之Iterator接口和for…of循环
- centos7下关于拨号上网的一点问题
- spring轻松实现数据源动态切换
- DDX_Control与DDX_Check
- 进行前端性能优化几种常用的方法。
- OpenCV全局/局部阀值二值化
- Spring:@Autowired注解、@Resource注解和@Service注解
- [Leetcode] 406. Queue Reconstruction by Height 解题报告
- JAVA RPC学习