首页 > 代码库 > Es6 之for of

Es6 之for of

 

 

能工摹形,巧匠窃意。 -- 毕加索

 

let nicknames = [‘di‘, ‘boo‘, ‘punkeye‘];nicknames.size = 3;for (let nickname of nicknames) {  console.log(nickname);}Result: di, boo, punkeyefor...in 用来遍历对象中的属性:
let nicknames
= [‘di‘, ‘boo‘, ‘punkeye‘];nicknames.size = 3;for (let nickname in nicknames) { console.log(nickname);}Result: 0, 1, 2, size


 

 

对比方可以看到这一微弱的变化 所引发的美感!

let nicknames = [‘di‘, ‘boo‘, ‘punkeye‘];nicknames.size = 3;for (let nickname of nicknames) {  console.log(nickname);}Result: di, boo, punkeyefor...in 用来遍历对象中的属性:let nicknames = [‘di‘, ‘boo‘, ‘punkeye‘];nicknames.size = 3;for (let nickname in nicknames) {  console.log(nicknames[nickname]);}Result:di, boo, punkeye 3 

 

Es6 之for of