Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140012

How to group by id array

$
0
0

Hello guys can you help me reduce arrays please. I have two arrays and I need group one of them by mid. Here you can find example

I have array of objects

  const arr = [
            { mid: 888, name: test },
            { mid: 888, name: test1 },
            { mid: 888, name: test2 },
            { mid: 777, name: test10 },
        ]

But I need group by mid and get something like this

 const arr = [
            {
                mid: 888,
                projects: [
                    {name:test},
                    {name:test1},
                    {name:test2},
                ]
            },
            {
                mid: 777,
                projects: [
                    {name: test10},
                ]
            }
        ]

Viewing all articles
Browse latest Browse all 140012

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>