Skip to content
Advertisement

Vue / JavaScript – How to push dynamic object to array

I have this data:

JavaScript

My Goal is to build a table using that data where the table header will be the object key and value will be that corresponding object keys value.

**What I am doing **

First I get the key from the first object and store it to productKeys :

JavaScript

Now, I am adding that keys to columns:

JavaScript

Now, I can see the table header. Its time to set the corresponding header value. To do that, I am doing:

JavaScript

BUT, It doesn’t set the table cell value to that corresponding header. Currenlty the output is something like this: https://prnt.sc/Z3QHK5ZI6-Ib

Its should be fill up all the rows. I think the issue is at this line

JavaScript

Can you tell me how can I solve it?

Advertisement

Answer

Running 3 loop is not required, you already have a key array. just use that

JavaScript

Although I would suggest to handle some of the calculations in backend API, such that you at least get the key array from backend to be more efficient.

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