比如有个 数组`let array = [{ date: '2016-05-02', name: 'Ethan', status: 'success', total: '81'},{ date: '2016-05-04', name: 'Lynn', status: 'fail', tag: '50'},{ date: '2016-05-01', name: 'Kevin', status: 'success', tag: '20'}]`过滤条件:`let filters = { name: ['Lynn', 'Kevin'], status: ['success']}`想要的结果是同时满足 name 是 Lynn或者Kevin 同时 status是success的数据 请问怎么写比较有效率 谢谢
查看完整描述
TA贡献1842条经验 获得超12个赞
let keys = Object.keys(filters)
let result = array.filter(item => {
return keys.every(key => filters[key].indexOf(item[key]) !== -1)
})
查看完整回答