Skip to content
Advertisement

Error when creating array of objects in a javascript loop

I have a problem creating an array of objects. the problem is that you should only create 2 objects but you end up creating 8 objects, because each value of a property is inserted into a new object. I have an array of objects called columns, which is dynamic since the values and properties are changing

enter image description here
what I need is to create objects depending on the value of the row property, for example an object that only contains the same value of the row.

JavaScript

With this code I try to create my 2 objects, but unfortunately more objects are created than desired.

JavaScript

enter image description here
but as an attachment in the image 8 objects are created and only one property is filled and the correct thing would be this only 2 objects with these values.

JavaScript

JavaScript

I need some solution or recommendation on what I can do or what I can change from my code to make what I’m trying to do easier.

Advertisement

Answer

You have to filter columns based on criteria and reduce the result into an object.

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