法一:使用for…in…循环
var obj = {'0':'a', '1':'b', '2':'c'};
for(let i in obj){
console.log(i,":",obj[i]);//{0:a,1:b,2:c}
}
法二:使用Object.keys遍历
var obj = {'0':'a', '1':'b', '2':'c'};
Object.keys(obj).forEach(function(key){
console.log(key,obj[key]);//{0:a,1:b,2:c}
}
法三:使用getOwnPropertyNames遍历
var obj = {'0':'a','1':'b','2':'c'};
Object.getOwnPropertyNames(obj).forEach(function(key){
console.log(key,obj[key]);
});