I have two arrays
var arr1 = [
{'id':'1','name':'test1','value':'star','role':['monitor']},
{'id':'2','name':'test2','value':'player','role':['monitor','Supervisor']},
{'id':'3','name':'test3','value':'saviour','role':['Supervisor']},
{'id':'4','name':'test4','value':'rock','role':['monitor']},
{'id':'5','name':'test5','value':'rocky','role':['boxer','monitor']}
]
var arr2 = ['Supervisor','monitor'];
I want to get the result where arr2 values is properly matched with arr1 roles values
Persons having both the category should be pushed to arr3.
So result should be {'id':'2','name':'test2','value':'player','role':['monitor','Supervisor']}
.
if arr2 has one value then we can use arr1.indexOf(arr2[0])!='-1'
but how to satisfy the "and" condition in the for
loop..
I don't want to use this if possible, but it's all I can think of:
if( arr1.indexOf(arr2[0])!='-1' && arr1.indexOf(arr2[1])!='-1'){
return arr1[i];
}