获得一串数组,如下:
var data = [
{"id":"1","name":"小刘","age":"25"},
{"id":"2","name":"小华","age":"24"},
{"id":"3","name":"小佳","age":"27"},
{"id":"4","name":"小王","age":"24"},
{"id":"5","name":"小何","age":"22"},
];
删除数组中age小于等于25岁的人,并返回新的数组:如下:
var data = [
{"id":"1","name":"小刘","age":"25"},
{"id":"3","name":"小佳","age":"27"},
];
var data = [
{"id":"1","name":"小刘","age":"25"},
{"id":"2","name":"小华","age":"24"},
{"id":"3","name":"小佳","age":"27"},
{"id":"4","name":"小王","age":"24"},
{"id":"5","name":"小何","age":"22"},
];
var data1 = []
data.filter(function(e){
if(e.age > 25){
data1.push(e)
}
})
console.log(data1) //{id: "3", name: "小佳", age: "27"}
var data = [
{"id":"1","name":"小刘","age":"25"},
{"id":"2","name":"小华","age":"24"},
{"id":"3","name":"小佳","age":"27"},
{"id":"4","name":"小王","age":"24"},
{"id":"5","name":"小何","age":"22"},
];
new_data = data.filter(function(element, index) {
return element['age'] >= 25;
});
console.log(new_data);