代码演示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<script>
/**
* 需求:
* 使用iterator遍历迭代map,set集合
*/
'use strcit';
var array = [3,2,4,5]
//打印下标
for (let x in array) {
console.log(x);
}
//打印值
for (let x of array) {
console.log(x);
}
//遍历map集合中的元素
var map = new Map([["zhu",1],["f",2],["zzz",3]]);
for (let x of map){
console.log(x)
}
//遍历set结合中的元素
var set = new Set([7,8,9]);
for (let x of set){
console.log(x)
}
</script>
<body>
</body>
</html>