js中获取对象的属性名称
2020-10-21 本文已影响0人
小白的踩坑日常
法1、
function getObjKeys() { var obj = {
"name": "zhangsan",
"age": 30
};
let keys = Object.keys(obj);
console.log(keys);
}
法2、
function getObjKeysByfor() {
var keys = [];
var obj = {
"name": "zhangsan",
"age": 30
};
for (let key in obj) {
keys.push(key)
}
console.log(keys);
}
摘自:https://blog.csdn.net/xinusuoshu/article/details/63683706