I've got this little module that returns basic user data required for a web app that's extracted from a large number of columns per row. I was asked to replace the small, column specific select statement I'd prepared with a stored procedure that returns the entire row. This moves column pruning into the server. I've modified my original function to work as expected with the code below, but it feels like I could be doing better with Array.find((e) => {})sqlRequest.on('row', function(columns) {  response = {};  const keys = ['id', 'fn', 'ln', 'ctr'];  columns.forEach(function (c) {    let key = String(c.metadata.colName).toLowerCase();    if (keys.find((e) => { return key === e})) {      let value = String(c.value).charAt(0).toUpperCase() + String(c.value).slice(1).toLowerCase();      response[key] = value;    }  });});
Pruning unwanted columns from a selected row
javascript
response is an implicit global, which is a no-no. Now, I imagine it is declared in a wider scope already, but it's still disconcerting to see a function have such crass side-effects. It just overwrites the entire response variable (but if other functions have their own references to the previous value, they won't know about the overwriting).I'd use a callback or a promise to return a fresh object, and let some other piece of code deal with whether to redefine response.Your find call can be reduced to keys.find(e => key === e) - you don't need braces or return for one-line statements, or parentheses around a single parameter. But the more conventional way to do things is using indexOf. I.e.if(keys.indexOf(e) !== -1)