let list = [4, 5, 6];
for (let i in list)
{
console.log(i); // "0", "1", "2",
}
for (let i of list)
{
console.log(i); // "4", "5", "6"
}
简而言之,for..of 中遍历打印出的是值 ,for..in遍历打印出来的是索引
两者更多的区别和应用可以查看官网文档:
https://www.tslang.cn/docs/handbook/iterators-and-generators.html