//字符串
let str = "123";
for (let x of str) {
console.log(x);
}
//数组
let arr = ["a", "b", "c"];
for (let y of arr) {
console.log(y)
}
//Set结构
let sets = new Set(["d", "e", "f"]);
for (let z of sets) {
console.log(z);
}
//Map 结构
let maps = new Map();
maps.set("abc", "888888");
for (let w of maps) {
console.log(w);
}
//对象
// 报错了 objs is not iterable == 对象没有iterable 所以 不能遍历
let objs = { "name": "gao", "age": 18 };
for (let q of objs) {
console.log(q);
}
for of循环
最新推荐文章于 2023-10-23 10:40:34 发布