for in,for of遍历
const obj = {
name: 'Jack',
age: '18',
gender: '男'
}
for (key in obj) {
console.log(key)//name age gender
console.log(typeof key)//string string string
console.log(obj[key])//Jack 18 男
console.log(obj['key'])//undefined undefined undefined
}
const array=[2,4,6,8] for(val in array){ console.log(val)//0,1,2,3,(下标) } for(arr of array){ console.log(arr)//2,4,6,8(遍历数组中的值) }