I am faced with a challenge of handling an array of complex objects, some of which may contain arrays of more objects. My goal is to convert this data into a CSV file. However, whenever there is a list of objects, the information appears as [object Object]
. For instance, if a person has multiple email addresses, I would like each email to be displayed on a separate line. Similarly, addresses may need to be concatenated into a single string format, like "France, Paris, someStreet 15".
You can find the code for this task in this pen.
Below is a snippet of the data:
var names = [
{
Name: [{First: "Peter", Last:"john"}],
WorkPlace: [{Company: "Intel", emails: ["<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94fef5f7ffd4fdfae0f1f8f8baf7fbf9">[email protected]</a>","<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5637323b3b3a16">[email protected]</a>"]}],
Age: 33.45,
Adress: [{Country:"UK", city: "London", street:"Oak", strtNumber:16},
{Country:"Italy", city: "MIlan", street:"Zabin", strtNumber:2}]
},
{
Name: [{First: "jack", Last:"Smith"}],
WorkPlace: [{Company: "Intel", emails: ["<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="86ece7e5edc6efe8f2e3eaeaa8e5e9eb">[email protected]</a>","<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e180858c88a1888f95848d8dcf828e8c">[email protected]</a>"]}],
Age: 30,
Adress: [{Country:"Portugal", city: "Lisbon", street:"crap", strtNumber:144},
{Country:"Greece", city: "Athenes", street:"Hercules", strtNumber:55}]
},
{
Name: [{First: "jon", Last:"snow"}],
WorkPlace: [{Company: "Intel", emails: ["<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b2d8d3d1d9f2dbdcc6d7dede9cd1dddf">[email protected]</a>","<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f091949d99b0999e84959c9cde939f9d">[email protected]</a>"]}],
Age: 50,
Adress: [{Country:"Middle earth", city: "Winterfell", street:"raven", strtNumber:4345},
{Country:"Narnia", city: "Jacksonvile", street:"Great crap", strNumber:34}]
},
];
Currently, the output looks like this: