title: Array of objects in javascript not returning as expected
body: <p>I have a function which returns a list of objects in Javascript, and I'm calling this function from another and attempting to use some of the values from it, but whenever I try to access said values, they come back undefined.</p>
  
  <p>This is my function which generates the list - the idea is that it creates a sqlite3 database if it does not exist, and returns an array containing every event.</p>
  
  <pre><code>function listAllEvents() {
      const sqlite3 = require('sqlite3').verbose();
      const db = new sqlite3.Database('schedule.db');
  
      const selectionArray = [];
  
      db.serialize(() =&gt; {
          db.run(`
          CREATE TABLE IF NOT EXISTS todo (
              name text,
              date text,
              id text primary key
              )
          `);
  
          db.all('SELECT * FROM todo ORDER BY date', [], (err, rows) =&gt; {
              if (err) {
                  throw err;
              }
  
              rows.forEach((row) =&gt; {
                  selectionArray.push(row);
              });
          });
      });
      return selectionArray;
  }
  </code></pre>
  
  <p>I call this function from another, but when I try to access values from the array, they don't seem to be working and I can't quite figure it out.</p>
  
  <pre><code>function displayUpcomingEvents() {
      const events = listAllEvents();
  
      // console.log(events); &lt;-- This line here! In the console, it correctly states the length of the array
      // console.log(events.length) &lt;-- This line, however, returns 0. Why?
      // console.log(events[0]) &lt;-- This doesn't work either, it just returns "undefined".
  
      for (let i = 0; i &lt; events.length; i += 1) {
          $('#upcomingEvents').after('&lt;li&gt;asdf&lt;/li&gt;');
      }
  }
  </code></pre>
  
  <p>For example, if I were to create two events in the database, through the console, </p>
  
  <pre><code>events is an Array(2) with indices
  - 0: {name: "my_event", date: "2019-06-04", id: "c017c392d446d4b2"}
  - 1: {name: "my_event_2", date: "2019-06-04", id: "6d655ac8dd02e3fd"},
  
  events.length returns 0,
  and events[0] returns undefined.
  </code></pre>
  
  <p>Why is this, and what can I do to fix it?</p>