js 获取对象的属性名(key)列表
keys() 方法获取
values()可以获取键值列表
const person = {
name: "Bill",
age: 19,
eyeColor: "blue"
};
const keys = Object.keys(person);
console.log(keys)// ['name', 'age', 'eyeColor']
for in 语句获取
const person = {
name: "Bill",
age: 19,
eyeColor: "blue"
};
const keys = []
for(var k in person){
keys.push(k)
}
console.log(keys)// ['name', 'age', 'eyeColor']
getOwnPropertyNames() 方法获取
const person = {
name: "Bill",
age: 19,
eyeColor: "blue"
};
const keys = Object.getOwnPropertyNames(person)
console.log(keys)// ['name', 'age', 'eyeColor']