1 回答

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
的,或者需要some不every。
const res = stores.filter(store =>
Object.entries(filters).every(([key , value]) => value.some(e =>
store[key].includes(e)
)));
console.log(res);
<script>
const filters = {
country: ["France"],
type: ["toys", "electronics"],
language: ["English", "Spanish"]
};
const stores = [
{
name: "StoreA",
country: "United States",
type: ["toys", "groceries"],
language: ["English", "Spanish"]
},
{
name: "StoreB",
country: "Spain",
type: ["toys"],
language: ["Engilsh", "Spanish"]
},
{
name: "StoreC",
country: "France",
type: ["autoparts"],
language: ["French"]
},
{
name: "StoreD",
country: "Thailand",
type: ["toys"],
language: ["Thai"]
},
{
name: "StoreE",
country: "India",
type: ["toys"],
language: ["Engilsh"]
},
{
name: "StoreF",
country: "France",
type: ["toys"],
language: ["English", "French"]
},
];
</script>
另請(qǐng)注意您商店中的多個(gè)錯(cuò)別字,英語不會(huì)返回 true
添加回答
舉報(bào)