统计数组中重复数据

1、原数据如下console.log(arr)

0: {…}
1: {…}
2: {…}
3: {…}
4: {…}
5: {…}
6: {…}
7: {…}
8: {…}
9: {…}

2、遍历数组、获取数据

           for (let item of arr){
                console.log(item.householdRelation)
           }

3.遍历结果

  00
  10
3 00
  null 
4 00

4.准备空数组 let dictCodeArr = [];将遍历结果存到数组

           let dictCodeArr = [];
           for (let item of arr){
             dictCodeArr.push(item.householdRelation);
           }

5.在方法外添加方法,统计重复次数

       getWordCnt(arr){
           var obj = {};
           for(var i= 0, l = arr.length; i< l; i++){
               var item = arr[i];
               obj[item] = (obj[item] +1 ) || 1;
           }
           return obj;
       },

6.在return中定义变量

json:{},

7.存储数据

this.json = this.getWordCnt(dictCodeArr);

8.分条件显示

           if(this.json["00"] && this.json["00"] >= 2){
               this.$notify({
                   title: '提示',
                   message: '1、该户存在多个户籍地户主关系请工作人员前往楼房管理核查修改;',
                   type: 'warning'
               });
           } else if(this.json["10"] && this.json["10"]>=2){
               this.$notify({
                   title: '提示',
                   message: '1、与户籍地户主关系错误请工作人员前往楼房管理核查修改;',
                   type: 'warning'
               });
           } else if(this.json["00"] && this.json["00"] >= 2 && this.json["10"] && this.json["10"]>=2){
               this.$notify({
                   title: '提示',
                   message: '1、该户存在多个户籍地户主关系请工作人员前往楼房管理核查修改;2、与户籍地户主关系错误请工作人员前往楼房管理核查修改;',
                   type: 'warning',

               });
           };
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容