Skip to content
Advertisement

grouping elements for same object

this is a simplified array of objects with different elements( it’s a result from database). I’m trying to group classes together for each person so I can show it in an html table as final result, I’m using this after foreach loop:

JavaScript

I have tried parsing the Array with 2 for loops and if loop, but it didn’t work as expected. Please can anyone help me with that?

I would like to group id_class for same person

JavaScript

Advertisement

Answer

With the hint of RiggsFolly, I used also $previous to save the previous element in the current iteration and compare if it’s the same, so this is working:

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