我有這樣一組數據,我沒有控制(其託管API的地方,我都進不去)拉屬性對象作爲父對象
let x = [
{name: "james", age: 10, school: {id:1, name:"London"}},
{name: "james_2", age: 11, school: {id:1, name:"London"}},
{name: "john", age: 12, school: {id:2, name:"India"}},
{name: "johnny", age: 56, school: {id:3, name:"USA"}}
]
我怎能組全校第一?我需要的格式是這樣
[{
id:1,
name: "London",
data: [{
name: "james", age: 10, school: {id:1, name:"London"
},{name: "james_2", age: 11, school: {id:1, name:"London"}}]
}]
什麼是這個? _(數據) –
組[0] .school爲什麼在這裏使用[0]? –
_(數據)啓動一個lodash鏈。 group [0] .school用於從組的第一個元素中獲取學校名稱和ID。 –