循环:
let arr = [1,45,15,23,54,87,7,6,2];
for (let index in arr) {
console.log(index); //遍历索引
console.log(arr[index]); //遍历数组
}
for(let num of arr){ //遍历Map,Set等
console.log(num); //遍历数组
}
arr.forEach(function (value) {
console.log(value);
})
Map与Set
Map:一个key只能对应一个value值,如果在进行赋值,就会覆盖之前的值
let map = new Map([[key:value]]);
map.set('key',value); //添加
map.has('key'); //key是否存在与map中,返回值为true或者false
map.get('key'); //通过key获取其值
map.delete('key'); //删除
Set:无序,自动去重的集合
let arr = new Set([1,1,2,3]);
arr.add(); //添加
arr.delete(); //删除
arr.has(); //是否存在 ,返回值为true或者false