js获取数组对象再多数组中出现次数

    firstArr: [
        { gpjc: 1 },
        { gpjc: 2 },
        { gpjc: 3 },
        { gpjc: 4 },
        { gpjc: 5 },
        { gpjc: 6 },
        { gpjc: 7 },
      ],
      nextArr: [
        [{ gpjc: 1 }, { gpjc: 2 }, { gpjc: 6 }, { gpjc: 4 }, { gpjc: 5 }],
        [{ gpjc: 1 }, { gpjc: 2 }, { gpjc: 6 }, { gpjc: 4 }],
        [{ gpjc: 1 }, { gpjc: 3 }, { gpjc: 6 }, { gpjc: 5 }],
        [{ gpjc: 1 }, { gpjc: 2 }, { gpjc: 6 }],
        [{ gpjc: 1 }, { gpjc: 6 }, { gpjc: 2 }],
        [{ gpjc: 1 }, { gpjc: 2 }],
        [{ gpjc: 1 }],
      ],
  getNum() {
      let one = this.firstArr;
      let two = this.nextArr;
      for (let i = 0; i < one.length; i++) {
        one[i].have = 0;
        for (let j = 0; j < two.length; j++) {
          for (let k = 0; k < two[j].length; k++) {
            if (one[i].gpjc === two[j][k].gpjc) {
              one[i].have++;
            }
          }
        }
      }
      function sortData(a, b) {
        return b.have - a.have;
      }
      one.sort(sortData);
      console.log(one);
      this.haveNums = [...one];
    },

 

posted @ 2021-08-24 15:56  ThisCall  阅读(441)  评论(0编辑  收藏  举报