js中遍历对象的方式
for…in…
let object = {
first: '12',
second: 13
}
for (let item in object) {
console.log(item) // 'first','second'
console.log(object[item]) //'12',13
}
Object.key遍历
let object = {
first: '12',
second: 13
}
Object.keys(object) // 'first','second'
Object.keys(obj).forEach((key) => {
console.log(obj[key]) // '12',13
})
Object.values遍历
let object = {
first: '12',
second: 13
}
Object.values(object) //'12',13