我们可以使用JavaScript中的Array.filter()和Array.every()方法来解决这个问题。
首先,我们需要将arrA中的所有字符串转换为小写,并将其保存到另一个数组arrALower中。这是因为我们需要比较不区分大小写的字符串。
然后,我们可以使用filter()方法来筛选出与arrALower中的所有字符串匹配的arrB对象。在这个筛选过程中,我们可以使用every()方法来确保arrB对象的所有属性键都匹配arrALower中的某个字符串。
以下是完整的代码解决方案:
const arrA = ["foo", "bar", "baz"]; const arrB = [ { foo: 1, qux: "hello" }, { bar: 2, qux: "world" }, { baz: 3, qux: "foo" }, { qux: "bar" }, ];
const arrALower = arrA.map((str) => str.toLowerCase());
const result = arrB.filter((obj) => { return arrALower.every((str) => { return Object.keys(obj).some((key) => key.toLowerCase() === str); }); });
console.log(result);
输出结果:
[{foo: 1, qux: "hello"}, {bar: 2, qux: "world"}, {baz: 3, qux: "foo"}]