我想将所有项目的列表与相同的companyName
和companyId
.
我需要帮助处理数据,以便它将具有相同值的所有数据用于companyName
并将companyId
其组合到自己的数组中。
我期望的输入示例数据将在这里:
[{
"companyName": "ABC company",
"companyId": "123",
"projectName": "project1",
"levelCode": "893",
"projectStatus": "2"
},
{
"companyName": "ABC company",
"companyId": "123",
"projectName": "project2",
"levelCode": "1386",
"userId": "183",
"projectStatus": "2"
},
{
"companyName": "ABC company",
"companyId": "123",
"projectName": "project3",
"levelCode": "1655",
"userId": "183",
"projectStatus": "1"
},
{
"companyName": "ABC company",
"companyId": "123",
"projectName": "project4",
"levelCode": "1865",
"userId": "159",
"projectStatus": "2"
}]
预期产出
处理完所有数据后:请注意,所有涉及companyName
“ABC 公司”的项目现在都合并为一个数组(项目)。
[
{
"companyName": "ABC company",
"companyId": "123",
"projects": {
"projectName": "project1",
"levelCode": "893",
"projectStatus": "2"
},
{
"projectName": "project2",
"levelCode": "1386",
"userId": "183",
"projectStatus": "2"
},
{
"projectName": "project3",
"levelCode": "1655",
"userId": "183",
"projectStatus": "1"
},
{
"projectName": "project4",
"levelCode": "1865",
"userId": "159",
"projectStatus": "2"
}
}
]