What is the problem of merging javascript multi-dimensional arrays?

            var arr = [{
                id: 1,
                name: "a"
            }, {
                id: 1,
                name: "b"
            }, {
                id: 2,
                name: "c"
            }, {
                id: 2,
                name: "d"
            }];

implementation result:

arr = [{
                id: 1,
                name: ["a", "b"]
            }, {
                id: 2,
                name: ["c", "d"]
            }];

could you tell me how to achieve this?

Mar.21,2021

  

my sentence is a bit less readable, for reference:
arr.reduce ((mjournal c) = > [m.find (x = > x.id=c.id) .name.push (c.name), m] [1], Array.from (new Set (arr.map (n = > n.id)), m = > new Object ({id:m,name: []});

Menu