Gabriel M Fernandes Gabriel M Fernandes - 6 months ago 14
Node.js Question

Node.js map returning result between quotes and brackets in Slack window

I am building a Slack app that has a slash command for displaying data from the database using

pg-promise
module like this:

select: () =>
rep.map(sql.select, null, row => {
return 'User ' + row.username + ' is ' + row.status;
}),


Like this, an array of rows is returned, but the result is always like:

["User username1 is status1", "User username2 is status2", ...]


I need it to be displayed in a list, without these quotes and brackets.

User username1 is status1
User username2 is status2
...


I've tried to
replace
using regex, but it doesn't work.

Answer

If your intent is simply to display the resulting strings:

var os = require('os');

rep.map(sql.select, null, row => {
    return 'User ' + row.username + ' is ' + row.status;
})
    .then(data=> {
        console.log(data.join(os.EOL));
    });

Database.map resolves with a new array of returned values, the same as your regular Array.map