var arr = { "name" : "zh", "age" : 22, } for(var key in arr){ //if(arr.hasOwnProperty(key)) console.log(key); //键名 console.log(arr[key]); //键值 }
输出是
"name"
"zh"
"age"
22
js实现获取对象key名
原文:https://www.cnblogs.com/wxcbg/p/10453215.html