Hello people, I have this function that I use to analyze some texts, the problem is that I need to include the data in an array, I do this inside the function using data, which is brought by this function, but then the 'sentiments' variable remains empty, and I can't use it outside the function, what would be the way to get sentiments to be pushed and get the results to the callback?
for(var i=0; i<texts.length; i++){
ibmWatson.analize(texts[i], function (error, data)
{
sentiments.push(data.result);
});
}
callback(null, sentiments);
You need to make sure that the function has been executed as many times as necessary. Your loop doesn't actually execute it, it simply declares its execution N times where N is
texts.length
:Simplified example of execution: