Skip to content
Advertisement

separate json object into different index

I have following array which consist of json objects:

JavaScript

I want to separate the array index for each same id

as an example :

JavaScript

How to do like that ? thanks

Advertisement

Answer

you can use reduce to group by id and then the values of the resultant using Object.values
EDIT
??= is the Logical nullish assignment. The right hand side will be assigned whenever the left hand side is null or undefined.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement