# 循环相关函数

# for in循环

  • key 是 obj的key值,为string类型
  • for in 循环遍历会顺着原型链查找。
let c = Object.create({name:'kira',age:20});
console.log(c);//{}
console.log(c.__proto__);//{name:'kira',age:20}
    for(let key in c){
        console.log('---key',key)
    }

# 用for in 或者for of循环数组

//获取到的key是string类型的索引
let arr = [1,2,3,4];
for(let key in arr){
    console.log(key);
}
//for in会遍历到数组或者对象的原型链上
let arr = [1,2,3,4];
arr.prototype.fn = function(){}
for(let key in arr){
    console.log(key);
}
//打印结果
//0 1 2 3 fn

//获取到的key是数组的item当前项
for(let key of arr){
    console.log(key);
}