js mysql getting table (object) keys

45 views
Skip to first unread message

Mihajlo Spasic

unread,
Sep 30, 2022, 10:50:17 PM9/30/22
to node-mysql
I'm interested in getting the table keys. For example, I want to get the column names when looping through a table. I thought that results[key] would provide me that but I was mistaken. I read the documentation but I didn't find what I needed, even if it is there I probably just didn't understand it.
DBconnection.query("SHOW TABLES", function (error, results, fields) {
  if (error) console.error(error);
  for (let result in results) {
    for (const key in results) {
      console.log(`${key}: ${results[key]}`);
    }
  }
  console.log(results);
});
Reply all
Reply to author
Forward
0 new messages