Answer the question
In order to leave comments, you need to log in
How to pass an array of data from the database to a method?
There is this code:
let queryString = 'SELECT * FROM products';
connection.query(queryString, function (err, results) {
for (let i in items) {
let products = [{
"id":items[i].id,
"name": items[i].name,
"price": items[I].price
}];
}});
link.addProducts(products);
link.addProducts(products);
?
Answer the question
In order to leave comments, you need to log in
Why not do this in the callback function?
let queryString = 'SELECT * FROM products';
connection.query(queryString, function (err, results) {
for (let i in items) {
let products = [{
"id":items[i].id,
"name": items[i].name,
"price": items[I].price
}];
}
link.addProducts(products);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question