1.for in 循环 并且使用hasOwnProperty 方法
var jsonObject1 = {
"name": "xiaoming",
"age": 29
},
var keys1 = [];
for (var p1 in jsonObject1) {
if (jsonObject1.hasOwnProperty(p1))
keys1.push(p1);
}
alert(keys1);
如果不使用 hasOwnProperty,给Object 添加自己的属性时,也会输出出来
Object.prototype.test = "I am test";
var jsonObject = {
"name": "xiaoming",
"age": 29
},
keys = [];
for (var p in jsonObject)
keys.push(p);
alert(keys); //name,age, test
来源:CSDN
作者:qq_37390420
链接:https://blog.csdn.net/qq_37390420/article/details/103984527