ES6中for...of的容易运用案例
发表时间:2025-11-09 来源:浏览器大全整理相关软件相关文章人气:
网页的本质就是超级文本标记语言,通过结合使用其他的Web技术(如:脚本语言、公共网关接口、组件等),可以创造出功能强大的网页。因而,超级文本标记语言是万维网(Web)编程的基础,也就是说万维网是建立在超文本基础之上的。超级文本标记语言之所以称为超文本标记语言,是因为文本中包含了所谓“超级链接”点。
本篇文章给大家带来的内容是关于ES6中for...of的简单使用实例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
概述
for...of是一个迭代可迭代对象的方式,可迭代对象包括Array、Map、Set、String、TypedArray、arguments 对象等等
语法
for(variable of iterable){
// statement
}迭代数组
for(let a of [1,2,3]){
console.log(a)
}
// 1
// 2
// 3迭代字符串
for(let s of 'hello'){
console.log(s)
}
// h
// e
// l
// l
// o迭代Set
for(let s of new Set([1,2,3])){
console.log(s)
}
// 1
// 2
// 30x004 迭代Map
for(let s of new Map([[1,1],[2,2]])){
console.log(s)
}
// (2) [1, 1]
// (2) [2, 2]迭代arguments
(function() {
for (let argument of arguments) {
console.log(argument);
}
})(1, 2, 3);迭代Dom集合
for(let p of document.getElementsByTagName('p')){
console.log(p)
}
// <p>...<p>
// <p>...<p>
// <p>...<p>
// <p>...<p>
...总结
for...of只能迭代可迭代对象
以上就是ES6中for...of的简单使用实例的详细内容,更多请关注php中文网其它相关文章!
网站建设是一个广义的术语,涵盖了许多不同的技能和学科中所使用的生产和维护的网站。