Search code examples
javascriptarraysobjectalasql

Retrieve value of column using AlaSQL


I guess my Javascript is not strong enough and I cannot find any examples online, if I have this:

alasql.options.autocommit = true;
alasql("CREATE localStorage DATABASE IF NOT EXISTS lsdb");
alasql("ATTACH localStorage DATABASE lsdb");
alasql("USE lsdb");
alasql("CREATE TABLE IF NOT EXISTS people (Id INT,FirstName STRING,LastName STRING)");
alasql("INSERT INTO people VALUES (1,'Peter','Peterson'), (2,'Eric','Ericson'), (3,'John','Johnson')");
res = alasql("SELECT * FROM people;");

How do I retrieve values using the column name?

Something like res[0].FirstName ? But that doesn't work. Is that possible using AlaSQL?


Solution

  • This did the trick, seems like ChatGPT is getting to be my best friend ;-)

    for (var i = 0; i < res.length; i++) {  
      var row = res[i];
      console.log(row['FirstName']);
    }