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