V
V
vialonchele2018-06-30 12:23:24
Node.js
vialonchele, 2018-06-30 12:23:24

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);

How to send array products to link.addProducts(products);?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2018-06-30
@alexalexes

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 question

Ask a Question

731 491 924 answers to any question