// conditionArr: 查询条件
var conditionArr=[{
name:'广州',
type:'area'
},{
name:'一本',
type:'batch'
}];
// 查询数组
var dataArr=[{
name:'广州大学1',
area:'广州',
batch:'一本'
},{
name:'广州大学2',
area:'广州',
batch:'一本'
},{
name:'广州大学3',
area:'深圳',
batch:'一本'
},{
name:'广州大学4',
area:'深圳',
batch:'二本'
},{
name:'广州大学5',
area:'广州',
batch:'二本'
},{
name:'广州大学6',
area:'广州',
batch:'二本'
}];
实现方法:
var temp=[],bool; for(let item of dataArr){ bool = true for(let j of conditionArr){ if (item[j.type] !== j.name){ bool = false; } } bool && temp.push(item) } console.log(temp);