Users:[ { name: 'tom', age:26, email:"1@qq.com", address:"河北" }, { name: 'tom', age:23, email:"2@qq.com", address:"山东" }, { name: 'tom', age:24, email:"3@qq.com", address:"河北" }, { name: 'mike', age:25, email:"4@qq.com", address:"河北" } ]let searchObj = { name: "tom", address:"河北", age:24}我想输出一个新的数组,符合name为tom address为河北 并且age>24的符合条件的对象,应该怎么筛选?
4 回答
慕桂英546537
TA贡献1848条经验 获得超10个赞
function filter (source, keyObj) {
let keys = Object.keys(keyObj)
return source.filter(v => {
return keys.every(key => v[key] === keyObj[key])
})
}
filter(Users, searchObj)
添加回答
举报
0/150
提交
取消