Javascript 如何使用angular6根据字符串数组过滤对象数组

Javascript 如何使用angular6根据字符串数组过滤对象数组,javascript,Javascript,我有两个字符串数组和一个对象数组。我需要根据2个字符串数组进行筛选。我怎样才能做到这一点 let profissionals = [ {state:'ap',type:'maths',price:200}, {state:'ap',type:'english',price:400}, {state:'ka',type:'social',price:200}, {state:'ts',type:'english',price:200}, {state:'ap',type:'maths',price

我有两个字符串数组和一个对象数组。我需要根据2个字符串数组进行筛选。我怎样才能做到这一点

let profissionals = [
{state:'ap',type:'maths',price:200},
{state:'ap',type:'english',price:400},
{state:'ka',type:'social',price:200},
{state:'ts',type:'english',price:200},
{state:'ap',type:'maths',price:500},
{state:'ka',type:'maths',price:600},
{state:'ts',type:'english',price:200},
{state:'kl',type:'english',price:100},
{state:'kl',type:'english',price:300},
{state:'ap',type:'social',price:200},
{state:'gj',type:'english',price:600},
{state:'kl',type:'social',price:600}
]

let typeList=['maths','social'];
let stateList=['ap','ka'];
输出应该是这样的

fliteredlist  = [
{state:'ap',type:'maths',price:200},
{state:'ap',type:'maths',price:500},
{state:'ka',type:'maths',price:600},
{state:'ap',type:'social',price:200},
{state:'ka',type:'social',price:200},
]

您可以使用
Array.filter()

let profissionals=[
{state:'ap',type:'math',price:200},
{州:'ap',类型:'english',价格:400},
{州:'ka',类型:'social',价格:200},
{state:'ts',type:'english',price:200},
{state:'ap',type:'math',price:500},
{state:'ka',type:'math',price:600},
{state:'ts',type:'english',price:200},
{州:'kl',类型:'english',价格:100},
{州:'kl',类型:'english',价格:300},
{状态:'ap',类型:'social',价格:200},
{state:'gj',type:'english',price:600},
{状态:'kl',类型:'social',价格:600}
]
让typeList=[‘数学’、‘社交’];
让stateList=['ap','ka'];
让输出=profissionals.filter({type,state})=>
(typeList.length==0 | | typeList.includes(type))
&& 
(stateList.length==0 | | stateList.includes(state));

控制台日志(输出)“如何实现?”->使用一些循环。也就是说。。。到目前为止,您自己尝试了什么来解决这个问题?@Rupesh这里是您需要的确切解决方案,谢谢,但是如果stateList是空数组。让typeList=[‘数学’、‘社交’];让stateList=[];我需要得到所有的数学和社会元素[{state:'ap',type:'math',price:200},{state:'ka',type:'social',price:200},{state:'ap',type:'math',price:500},{state:'ka',type:'math',price:600},{state:'ap',type:'social',price:200},{state:'kl type:'social',price:600}]@鲁佩什,我没有得到you@Rupesh这里是您需要的精确解决方案,例如在两个数组中,一个是空的。类型列表=['数学','社会'],状态列表=[]。这里typeList有数学值和社会值,但statelist没有任何值。在这种情况下,输出应为。像这样[{州:'ap',类型:'math',price:200},{州:'ka',类型:'social',price:200},{州:'ap',类型:'math',price:500},{州:'ka',类型:'math',price:600},{州:'ap',类型:'social',price:200},{州:'kl类型:'social',price:600}]
profissionals.filter(({state, type}) => stateList.includes(state) && typeList.includes(type));