我正在接收下一个数据。
我希望通过id合并它,并将rName推入一个数组中,以获得这种结构。
[
{ id: "1", name: "test1", rName: "the1" },
{ id: "1", name: "test1", rName: "the2" },
{ id: "1", name: "test1", rName: "the3" },
{ id: "2", name: "test2", rName: "the1" },
{ id: "2", name: "test2", rName: "the2" },
{ id: "3", name: "test3", rName: "the1" }
]
我希望通过id合并它,并将rName推入一个数组中,以获得这种结构。
[
{ id: "1", name: "test1", rName: ["the1", "the2","the3"] },
{ id: "2", name: "test2", rName: ["the1", "the2"] },
{ id: "3", name: "test3", rName: ["the1"] }
]
我曾尝试使用reduce方法,但未能成功,如果有人能指导我正确的方向,将不胜感激。