var a = ['A', 'B', 'C'];
for(var i of a.keys()) {
console.log(i)
}
for (var i of a) {
console.log(i)
}
a.forEach(function (element, index, array) {
console.log(element + ', index = ' + index);
});
var s = new Set(['A', 'B', 'C']);
s.forEach(function (element, sameElement, set) {
console.log(`${element}${sameElement}`);
});
var m = new Map([[1, 'x'], [2, 'y'], [3, 'z']]);
m.forEach(function (value, key, map) {
console.log(`${value}${key}`);
});
var changes = {
name: 'virgo',
age: '27'
}
for (var key in changes) {
console.log(value = changes[key]);
}
对象,数组,Set,Map的遍历方法
最新推荐文章于 2023-12-20 19:23:37 发布