本篇文章给大家带来的内容是关于es6中for...of的简单使用实例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
for...of是一个迭代可迭代对象的方式,可迭代对象包括Array、Map、Set、String、TypedArray、arguments 对象等等
语法
weenCompany闻名企业网站系统(免费开源)是一个功能强大, 使用简单的中英文企业智能建站系统, 您只需要一些基本的计算机知识就可以利用此系统完成中小型企业网站的建设; 是低成本企业网站架设方案之首选CMS系统, 也适合建设个人网站。weenCompany闻名企业网站系统功能:1. 程序代码简洁严谨, 整个系统程序仅2M左右大小.2. 中英文双语版共用一套网站程序, 双语页面实现自由切换.3
0
for(variable of iterable){
// statement
}for(let a of [1,2,3]){
console.log(a)
}
// 1
// 2
// 3for(let s of 'hello'){
console.log(s)
}
// h
// e
// l
// l
// ofor(let s of new Set([1,2,3])){
console.log(s)
}
// 1
// 2
// 3Map
for(let s of new Map([[1,1],[2,2]])){
console.log(s)
}
// (2) [1, 1]
// (2) [2, 2](function() {
for (let argument of arguments) {
console.log(argument);
}
})(1, 2, 3);for(let p of document.getElementsByTagName('p')){
console.log(p)
}
// <p>...<p>
// <p>...<p>
// <p>...<p>
// <p>...<p>
...for...of只能迭代可迭代对象
以上就是ES6中for...of的简单使用实例的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号