请问如何把一个带有相同元素值的数组归类组成一个新的二维数组?
相关代码
let arr = [{
code: "China",
name: "xiaohuai"
},
{
code: "Africa",
name: "neiLuoBi"
},
{
code: "Asia",
name: "hanGuo"
},
{
code: "China",
name: "tnnyang"
},
{
code: "Africa",
name: "nanFei"
},
{
code: "China",
name: "yangMan"
}
]
归类为下面这种形式
let arr2 = [{
China: [{
name: "xiaohuai"
},
{
name: "tnnyang"
},
{
name: "yangMan"
}
],
Africa: [{
name: "neiLuoBi"
},
{
name: "nanFei"
}
],
Asia: [{
name: "hanGuo"
}]
}]