【发布时间】:2022-12-18 17:36:48
【问题描述】:
我有一个要过滤的对象的配置文件数组。过滤器是另一个数组中状态的组合。状态数组由用户定义。 Profiles 数组可以由用户使用一个或多个 Status 进行过滤。在不知道应该提前检查多少条件的情况下如何编写过滤函数?
//the array to filter
let profileList = [{name: "John", staus: "green"}, {name: "Alex", staus: "yellow"}, {name: "Jane", staus: "green"}]
//user defined: they can add up to 30 statuses
let statusList = ["green", "yellow", "red", "black"]
//also user defined: they can filter by as many statuses as they want
let filters = ["green", "red"]
const filteredProfileList = profileList.filter(element => {
return //how to write the conditions with logical OR (||) if I don't know how many statuses will be used?
});
【问题讨论】:
标签: javascript arrays