1 回答
TA贡献1812条经验 获得超5个赞
的,或者需要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>
另请注意您商店中的多个错别字,英语不会返回 true
添加回答
举报