首页 > 解决方案 > 我可以在 Javascript 的过滤器函数中使用两个包含方法吗?

问题描述

我可以在 Javascript 的过滤器函数中使用两个包含方法吗?

我想要一个没有这些状态的新数组(“活动”、“已退款”)。我怎样才能做到这一点?我正在考虑使用两种包含方法,但它似乎不起作用。

const availableModules = [
  {
    key: "tshirt",
    color: "#305b2d",
    status: "active",
    modules: 
    [
    { key: "tshirt",
    color: "#066da0",
    status: "active step 2"}, 
    {  key: "tshirt",
    color: "#772016",
    status: "active step 3"}
    ],
  },
  {
    key: "tshirt",
    color: "#742016",
    status: "canceled",
  },
  {
    key: "hat",
    color: "#201010",
    status: "refunded",
  },
 {
    key: "short",
    color: "#702213",
    status: "delivered",
  },
 {
    key: "short",
    color: "#702010",
    status: "Pending",
  },
 {
    key: "shirt",
    color: "#702411",
    status: "Closed",
  },
];


const seeOther = availableModules.filter(m=> console.log(!m.status.includes('active', 'refunded')))

标签: javascriptarraysalgorithm

解决方案


你试过这样

availableModules.filter(x => ((x.status !== "active") && (x.status !== "refunded")))

推荐阅读