Skip to content
Advertisement

Group associative row data based on shared column value

I have a multidimensional array like:

JavaScript

I need to find the rows with matching division values and merge them in one array.

From this array, I want the output as:

JavaScript

Keys in the subarrays can be different and the subarrays may have a differing number of elements.

Advertisement

Answer

I think it’s relatively simple to just iterate through the array and continuously merge the entries separated by “division”:

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