如何检查一个数组是否包含另一个数组?

时间:2020-01-31 14:27:19

标签: javascript arrays multidimensional-array

我尝试使用Array.includes,但是此代码返回false:

const data = [
  {
    date: "2019-11-04",
    transactionTypes: {
      type1: [
        { irrelevantObject1: "irrelevantObject1" },
        { irrelevantObject2: "irrelevantObject2" },
        { irrelevantObject3: "irrelevantObject3" },
        { irrelevantObject4: "irrelevantObject4" }
      ],
      type2: [
        { irrelevantObject1: "irrelevantObject1" },
        { irrelevantObject2: "irrelevantObject2" },
        { irrelevantObject3: "irrelevantObject3" }
      ]
    }
  }
];

const result = data.map(o => ({
  ...o,
  transactionTypes: Object.entries(o.transactionTypes).map(([k, arr]) => ({
    [k]: arr.length
  }))
}));

console.log(result);

有人知道我可以代替什么吗?

0 个答案:

没有答案