[ES6] for..in && for..of - Zhentiw - 博客园

复制代码; "复制代码")

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"
} */

复制代码; "复制代码")


Original url: Access
Created at: 2018-11-16 15:45:29
Category: default
Tags: none

请先后发表评论
  • 最新评论
  • 总共0条评论