TypeScript for循环 in和of

let arr: string[] = ["小昆虫1", "小昆虫2", "小昆虫3"];
// 遍历数组值
console.log("遍历数组值=========================");
for (let item of arr) {
    console.log(item);
}
// 遍历数组索引
console.log("遍历数组索引=========================");
for (let item in arr) {
    console.log(item);
}
// 遍历数组索引和值
console.log("遍历数组索引和值=========================");
for (let item in arr) {
    console.log(item, arr[item]);
}

https://github.com/smallinsect/MyJS/blob/main/TypeScript/for.ts

原文地址:https://www.cnblogs.com/xuqiulin/p/14600598.html