I am using an array map function to simplify an array of objects into a single string.
const formatEmails: (arr: { "default" : string }[]) => string = (arr: { "default" : string }[]) =>
arr.map(e => e["default"]).reduce((e, i) => e + i + "; ", "");
This method works well when the email only has the "default" key. But what if the email object contains additional keys like this:
person_emails: [{ "default": '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afdbcadcdb9eefdbcadcdb81ccc0c2">[email protected]</a>' }, { "home": '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e4a5b4d4a0c7e4a5b4d4a105d5153">[email protected]</a>' }, { "work": '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ffbeafcfbbccffbeafcfba1ece0e2">[email protected]</a>' }]
How can I modify my code to handle such cases and generate a string like this: "default:[email protected]; home:[email protected]; work:[email protected]"
Just to clarify, my code runs the formatEmails function each time we read a row from the data export like this:
args.rowData["person_emails"] = formatEmails(args.rowData["person_emails"]);