2020-08-12
一郁惜、for in
const obj = {
id:1,
name:'zhangsan',
age:18
}
for(let key in obj) {
console.log(key, obj[key]);
}
二戈抄、Object.keys(obj)歌懒、Object.values(obj)
const obj = {
id:1,
name:'zhangsan',
age:18
}
console.log(Object.keys(obj))
console.log(Object.values(obj))
三具壮、Object.getOwnPropertyNames(obj)
const obj = {
id:1,
name:'zhangsan',
age:18
}
Object.getOwnPropertyNames(obj).forEach(key => {
console.log(key, obj[key]);
})