I am pulling some email addresses data from our db to print to a file in our Node project. That code looks like this:
const sql = `${query}`;
let emailRecords = await this.mariaDB.query(sql);
let data = JSON.stringify(emailRecords);
fs.writeFileSync(appRoot + "/public/email-lists/staff-emails.json", data);
That gives me data that looks like this:
[ { email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' },
{ email: '[email protected]' } ]
What I want to do is get rid of the key/value pairs, and end up with an array of just email addresses, like so:
[ '[email protected]',
'[email protected]',
'[email protected]',
'[email protected]' ]
I'm not sure what's the best way to accomplish this, as 'filter()' is used to return a subset of the original array based on matching criteria. Here I want all of the original data, but trimmed like I describe above. Should I use regex here? Something else?