I'm trying to iterate through a value('test')
and sent it to a class function and push the returned value into an array('t')
. How can I wait for the for loop to finish and then print the array('t')
?
I tried using Promises
and function wrapper but to no use. Here is the code snippet:
t = []
test = ['1', '2']
for(var i in test) {
console.log('inside for loop')
new myFile.class(mysqlParams).myfunc(2, test[i], result=> {
t.push(result)
})
console.log('t: ' + t)
}
Can someone please help me?
Edit:
myfunc(num, test, callback) {
connectToMysqlDatabase()
connection.query(getTestcaseContentCommand, function(err, testContent) {
if (err) {
console.log(err)
}
else {
result(testContent[0]['testcaseContent'])
}
}