从数组对象内的groupby数据获取计数值

时间:2020-04-26 08:07:19

标签: javascript arrays lodash

所以我有这种数组

[{
        "id":35,
        "aktivis":{
            "id":450,
            "name":"A. Sri Nugroho Hadi",
            "active_job":{
                "id":491,
                "id_aktivis":450,
                "id_company":20,
                "company":{
                    "id":20,
                    "name":"Company 1"
                    }
                },
            }
        }
    },
    {
        "id":36,
        "aktivis":{
            "id":451,
            "name":"A. Sri Nugroho Hadi",
            "active_job":{
                "id":492,
                "id_aktivis":451,
                "id_company":21,
                "company":{
                    "id":21,
                    "name":"compnay 2"
                    }
                },
            }
        }
}]

并且我想将其转换为一个数组,以告知公司名称和这些公司内部的员工人数

[{
        "id":20,
        "name":"Company 1"
        "employee_count":1
    },
    {
        "id":22,
        "name":"Company 2"
        "employee_count":1
}]  

如果这些键和值位于对象内部,如何将它们分组?

0 个答案:

没有答案