• 根据id将集合分类



    <script>
    var ojbArray = [

    {name: 'a', age: 18, classId: 1 },

    {name: 'b', age: 19, classId: 2 },

    {name: 'c', age: 16, classId: 3},

    {name: 'e', age: 34, classId: 2},

    {name: 'f', age: 22, classId: 1},

    {name:'d', age: 26, classId: 1}
    ];
    const ClassObj ={};//定义班级对象
    ojbArray.map(item=>{//班级分类
    if(ClassObj[item.classId] == undefined ){
      ClassObj[item.classId] = new Array();
    }
    ClassObj[item.classId].push(item);
    });


    const ClassArr =[];
    Object.keys(ClassObj).forEach((item)=>{
    var obj = {
      classId:item,
      classInfo:ClassObj[item]
    }
    ClassArr.push(obj);//合成渲染的list数组

    })
    console.log(ClassArr)
    alert(JSON.stringify(ClassArr))

    </script>

  • 相关阅读:
    Many Equal Substrings CF
    Seek the Name, Seek the Fame POJ
    人人都是好朋友(离散化 + 并查集)
    建设道路
    day_30
    day_29作业
    day_29
    day_28
    day_27
    day_26作业
  • 原文地址:https://www.cnblogs.com/zht831143/p/12592863.html
Copyright © 2020-2023  润新知