1

in javascript (Angular)

trying to convert an array of objects into a csv file

the objects are like

{name:ab, phone:231}
{name:alex,email:[email protected]}
{name: john, phone: 342, email: [email protected]}

how to convert this object to csv so that im not losing any of the fields

2
  • 1
    These aren't valid objects. Commented Feb 27, 2019 at 16:04
  • you can use this module: npmjs.com/package/json2csv Commented Feb 27, 2019 at 16:25

1 Answer 1

1

You habe to create an array of keys to guarantee key order, then map that to the values and join them by a comma:

 ["name", "phone", "email"].map(k => obj[k]).join(",")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.