0
I’m trying to add values using push, turns out it’s not working...
Only works inside the code block connection.query().
Is there any way to access variables and add values to them outside this scope?
My current code:
let customers = []
connection.query("SELECT * FROM customers", async (error, data) => {
customers.push(data) // console.log(customers) aqui funciona
})
console.log(customers) // retorno => [] (vazio)
Have you tried using the
awaitin theconection.query? probably the.log console is running before thecustomers.push(data)– Saulo Felipe
In addition to the link above see also: https://answall.com/q/264291/112052
– hkotsubo
Yes, I tried even I would put the code here, but as it was the same return
[]I didn’t put– Tio Gê