1.for...in
const obj = { name:'李', age:16, gender:'男' } for(let key in obj){ console.log(key + ':' + obj[key]) }
name:李
age:16
gender:男
2. Object.keys(obj) Object.values(obj)
const obj = { name:'李', age:16, gender:'男' } console.log(Object.keys(obj)) console.log(Object.values(obj)) [ 'name', 'age', 'gender' ] [ '李', 16, '男' ]
3.Object.getOwnPropertyNames(obj)
const obj = { name:'李', age:16, gender:'男' } Object.getOwnPropertyNames(obj).forEach(function(key){ console.log(key + ':' + obj[key]) }) name:李 age:16 gender:男