Issue with for loop to add items to select box

Hi there, I am having this issue:
Trying to fill select box from query and cannot get items to iterate into dropbox.
Here the code:
// Perform a query
$query = ‘SELECT nickname FROM names’;

connection.query($query, function(err, rows, fields) {
console.log(“An error ocurred performing the query.”);
var x = document.getElementById(“mySlct”);
var option = document.createElement(“option”);

for (var i in rows) {
  option.text = rows[i].nickname;  


// Close the connection
// The connection has been closed

Code only puts one item (the last one) into select tag. I’ve tried a bunch of times to change the code to get it to work. No luck. Apparently, I need to study up on loop statements but there is not much on the web pertaining to mysql in Electron. Any help would be appreciated. Thanks

The statement is used to iterate over Objects that aren’t Array-like.
I don’t know what kind of object rows is but I would see if for...of works.
for...of goes over elements like a numerical for loop.

Thank you, I’ll give that a try.

1 Like