Skip to content
Advertisement

Group rows on one column and create nested array from another column

I have an array that looks like this:

JavaScript

What I want to do is group these elements in a table row if the same id value:

JavaScript

I know I have to use foreach for this one but the logic for grouping these elements in a single row is beyond me. Any help would be appreciated. Thanks in advance. I’ve started with this.

JavaScript

Advertisement

Answer

First group elements to subarrays, then output each subarray:

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