1、使用Object.key遍历
let obj={'0':'a','1':'b','2':'c'};
Object.keys(obj).forEach(function(key){
console.log(key,obj[key]);
});
2、使用for...in遍历
let obj={'0':'a','1':'b','2':'c'};
for(let i in obj){
console.log(i,":",obj[i]);
}
3、使用Object.getOwnPropertyNames(obj)遍历对象
let obj={'0':'a','1':'b','2':'c'};
Object.getOwnPropertyNames(obj).forEach(function(key){
console.log(key,obj[key]);
});
4、使用Reflect.ownKeys(obj)遍历对象
let obj={'0':'a','1':'b','2':'c'};
Reflect.ownKeys(obj).forEach(function(key){
console.log(key,obj[key]);
});