I have an array like this
arr1 =
[
{A: \'red\', B: \'blue\'},
{Q: \'green\', R: \'blue\'},
{B: \'green\', M: \'red\'},
{Q: \'white\', R: \'blue\
You can do this with fiter()
, some()
and every()
var arr1 = [{"A":"red","B":"blue"},{"Q":"green","R":"blue"},{"B":"green","M":"red"},{"Q":"white","R":"blue"}]
var filter = [{"A":"val","B":"someval"},{"B":"anothervalue","M":"value"}]
var result = arr1.filter(function(e) {
return filter.some(function(a) {
var keyE = Object.keys(e);
var keyA = Object.keys(a);
return keyE.length == keyA.length && keyE.every(function(k) {
return keyA.includes(k)
})
})
})
console.log(result)