文章地址: https://www.cnblogs.com/sandraryan/
// for in 遍历数组和对象 var Dog = { name: 'jack', age: 2, eat: function(){ console.log('eating'); } } // Dog.eat(); // console.log(Dog); for(k in Dog){ console.log(k); console.log(Dog[k]); }
一般变量用k 或者key
console.log(k);获取的是属性/方法名
console.log(Dog[k]); 获取的是属性方法值