0

hi all i have this code where i select data from a database and want to insert them as objects inside an array :

conn2.query('SELECT date, action FROM actions WHERE ?', [{
  issue_id: data.id
}], function(error, data2) {
  if (error) {
    showNotification('Error :' + error, 'danger', 'glyphicon glyphicon-tasks');
  } else {
    data2.forEach(function(data21) {
      res.push({
        "date": data21.date,
        "description": data21.action
      });
      console.log(res);
    });
  }
});

the problem is that the res is alwayes empty .... if i

console.log({"date": data21.date,"description": data21.action})

it give me the right object .... seems that the push is not write.

Edited: thanks every body i could't solve this problem so i used officegen which did the job nicely

3
  • are you seeing any errors in console? Commented Oct 23, 2016 at 17:34
  • Maybe the query returns noting and data2 is an empty array, thus res.push never gets called? Add console.log('data2', data2) to the beginning of the callback function. Commented Oct 23, 2016 at 17:53
  • !data Commented Oct 23, 2016 at 18:33

2 Answers 2

1

I think you must have not declared res as an array object res = [] Or maybe the data2 is empty

Sign up to request clarification or add additional context in comments.

1 Comment

console.log({"date": data21.date,"description": data21.action})
0

Can you try

res.push({date: data21.date,description: data21.action});
console.log(JSON.stringify(res));
console.log(res.toString());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.