//i是对象键值命
//obj[i]是对应的键值
},
2,可使用 Object.keys(object) object是你需要操作的对象
Object.keys()会返回一个存储对象中所有key值的数组
获取当前对象每个key对应的值使用 object[key]
var people = [
{ "name": "bob", "dinner": "pizza" },
{ "name": "john", "dinner": "sushi" },
{ "name": "larry", "dinner": "hummus" }
]
people.filter(function (person) {
if(person.dinner){
console.log(person.dinner)
}
if(person.name){
console.log(person.name)
}
})
var people1 = { "name": "bob", "dinner": "pizza" }
Object.keys(people1)
console.log(Object.keys(people1))
var jsonObj = {"1" : 50,"2" : 40,"3" : 40,"4" : 30,"5" : 20,"6" : 20,"7" : 20,"8" : 20,"9" : 20, "10" : 20}
var keyAry = []
var valueAry = []
for(var key in jsonObj){
keyAry.push(key)
valueAry.push(jsonObj[key])
}
console.log(keyAry)
console.log(valueAry)