Often in the project development easy to forget the object traversal method, or use too little, to strengthen learning, so I will record here, convenient for myself later review,

The for – the in traverse

For-ins are designed for traversing objects, not groups of numbers. (Disadvantages of traversal arrays: array index is a number, for-in traversal index “0”,”1″,”2″, etc is a string)

var arr = {'0':'a','1':'b','2':'c'};
for (var index in arr){
    console.log(arr[index]);
    console.log(index);
}
Copy the code

Object. The keys () traversal

Returns an array containing all of the object’s own (not inherited) enumerable properties (not including the Symbol property).

var obj = {'0':'a','1':'b','2':'c'};
Object.keys(obj).forEach(function(key){
  console.log(key,obj[key]);
});
Copy the code