JSFiddle - React, Tailwind, and code Playground
JavaScript
function whatIsInAName(collection, source) {
var compareArr1 = [];
var compareArr2 = [];
var finArr = [];
var finArr2 = [];
compareArr1 = Object.keys(source);
for (const item of collection) {
if (compareArr1.every(
function(x){return item.hasOwnProperty(x)})) {
finArr.push(item);
}
}
for (const item of finArr) {
if (compareArr1.some(
function(x){return
item[x] !== source[x]})) {
continue;
}
finArr2.push(item);
}
console.log(finArr2);
}
whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });