1

I have an array of objects. Some of their keys are identical but some of them exist only in one of the object:

const data =[
{id:123, name:foo, number:25},
{id:124, name:boo, number:35, blue:8},
{id:125, name:soo, number:40, red:10}
]

I want to convert my data into a CSV, so that the headers will include all keys. if key doesn't exists in the object its value should be null , see example below:

id name number blue red
123 foo 25 null null
124 boo 35 8 null
125 soo 40 null 10

I was able to achieve this with few loops , but the code is ugly :)

Thanks!

1
  • I was able to achieve this with few loops so what is your question here ? Commented Jun 12, 2022 at 18:12

1 Answer 1

1

Check if this solution applies to your problem.

Generate a csv file from a javascript array of objects

If you have any doubts in the process, just reply here. I'll try to help

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.