json object
[
dictprovinceVOList[{
areaId: 13257
cityAreaList:[
{
areaCode: "1853"
areaId: 13265
areaList:
firstLetter:"S"
langType:"zh_CN"
latitude:22.124049
longitude:
113.559954
parentId:13257
pinYin:"shengfangjigetangqu"
postCode:"820008"
sortValue:8
title:"圣方济各堂区"
},
{
...
}]
parentId: 0
sortValue: 34
title:"澳门特别行政区"
},{
areaId:13238
cityAreaList:[
{
areaCode: "1853"
areaId: 13265
areaList:
firstLetter:"S"
langType:"zh_CN"
latitude:22.124049
longitude:
113.559954
parentId:13257
pinYin:"shengfangjigetangqu"
postCode:"820008"
sortValue:8
title:"圣方济各堂区"
},{
...
}]
parentId:0
sortValue:33
title:"香港特别行政区"
}]
]
Get the following results. . The grouping is based on the cityAreaList field: firstLetter
{
"iniData":"S",
"cityAreaList":[
{
"areaCode":"1853","areaId": 372, ...
},
{...}
]
}
lodash should not have a one-step function
But there is a groupBy function that can be used for grouping
You can use a loop to combine the cityAreaList of all cities into an array
Then
The returned object is roughly of this structure
The key of this object is the "iniData" you want
The rest is simple
Use Object.keys() to get all keys of object
This newArr is the result you want