var array = new Object()
创建一个空对象用来存储你传的参数,就是每个点击事件都要传参且也要将参数存储起来
同时筛选里面也会涉及到清空参数以及删除某一个值,例子:
var array={"name": "xiaojiayu", "age": 24, "gender": "man","sex":""}
1、删除对象里某一个值
delete array.name
2、清空对象
for(var key in array){
delete array[key]
}
3、清除对象里空的键值对
for(var key in array){
if(array[key] === ""){
delete array[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)