【发布时间】:2019-12-23 16:27:18
【问题描述】:
我正在尝试过滤数组
const array = [{
city: "Fullerton",
routes: ["Route 1", "Route 2"],
state: "CA"
}, {
city: "Long Beach",
routes: ["Route 3", "Route 4"],
state: "CA"
}, {
city: "Huntington Beach",
routes: "Route 1",
state: "CA"
}];
通过另一个数组:
const routes = ["Route 1", "Route 3"];
但是,我无法过滤原始数组的路由项,因为它有数组和字符串作为其变量。有没有办法使用 routes 数组并过滤原始数组而不考虑变量类型?
另外,我希望这样,如果您选择其中一个路由,即使数组元素包含更多路由,它也会过滤数组。
【问题讨论】:
标签: javascript arrays filter