看一个例子

    var a = [1,2,3]
    for(let i in a) {
      console.log(i)
    }
    //0
    //1
    //2
    
    for(let i of a) {
      console.log(i)
    }
    //1
    //2
    //3

    注意点:

    for...in 遍历的是可枚举属性, 应谨慎用于遍历数组等对象

    for...in 遍历是无序的

    var c={a:1,1:2,c:4,b:5}
    for(let i in c) {
      console.log(i)
    }
    //1
    //a
    //c
    //b