• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
御弟哥哥
博客园    首页    新随笔    联系   管理    订阅  订阅
将数组对象里相同的属性值,只留下一项

let j = [1,2,3];
let g = [1,2,3];

let y = [
{
      a:'人',
      operationType:2
},
{
      a:'人',
      operationType:2
},
{
       a:'人',
       operationType:2
},
{
       a:'交警1',
       operationType:9
},
{
       a:'交警2',
       operationType:9
},
{
       a:'交警3',
       operationType:9
},
{
       a:'归档1',
       operationType:6
},
{
       a:'归档2',
       operationType:6
},
{
        a:'归档3',
        operationType:6
},
{
       a:'责任1',
       operationType:7
},
{
       a:'责任2',
       operationType:7
},
{
       a:'责任3',
       operationType:7
}

]

let   OBJ = {},
       OBJG = {},
       OBJZ = {};
y.map((ith,iths) => {
      if(ith.operationType==9){
              let item = ith.operationType;
             OBJ[item] = (OBJ[item] + 1) || 1;
             if(OBJ[9]>1){
                     y.splice(iths,j.length-1)
               }
         }

})

 


y.map((ith,iths)=>{
         if(ith.operationType==6){
               let itemS = ith.operationType;
              OBJG[itemS] = (OBJG[itemS] + 1) || 1;
              if(OBJG[6]>1){
                     y.splice(iths,g.length-1)
                }
            }
})

y.map((ith,iths)=>{
           if(ith.operationType==7){
                 let itemZ = ith.operationType;
                 OBJZ[itemZ] = (OBJZ[itemZ] + 1) || 1;
                 if(OBJZ[7]>1){
                      y.splice(iths,g.length-1)
                 }
            }
})

 

 

posted on 2021-09-24 16:09  御弟哥哥  阅读(235)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3