Es6 之for of
Posted 云の旋律
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Es6 之for of相关的知识,希望对你有一定的参考价值。
能工摹形,巧匠窃意。 -- 毕加索
let nicknames = [‘di‘, ‘boo‘, ‘punkeye‘];
nicknames.size = 3;
for (let nickname of nicknames) {
console.log(nickname);
}
Result: di, boo, punkeye
for...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, punkeye
for...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的主要内容,如果未能解决你的问题,请参考以下文章
15ES6 for Humans: The Latest Standard of JavaScript: ES2015 and Beyond