[ES6] for..in && for..of

var ary = [
  {
    id: 1,
    name: "Zhentian"
  },
  {
    id: 2,
    name: "Alice"
  }
];

 

for..in

Print out the props name

for(let person in ary){
  console.log(person);  // "0", "1"
}

 

for..of

Print out the value

for(let person of ary){
  console.log(person); 
}

/*
[object Object] {
  id: 1,
  name: "Zhentian"
}
[object Object] {
  id: 2,
  name: "Alice"
}
*/

 

posted @ 2015-12-26 18:03  Zhentiw  阅读(578)  评论(0编辑  收藏  举报