How to get return value from callback function in Node : <p>The <code>get_customers()</code> function queries the database for the <code>playlists</code> records and logs to the console each row. But the <code>data</code> array is returned as an empty list array. How to return the data from the get_playlists function? </p>

<pre><code>...result undefined
</code></pre>

<pre><code>const sqlite3 = require('sqlite3').verbose();

let db = new sqlite3.Database('mydb.db', (err) =&gt; {
  if (err) {
    console.error(err.message);
  }
  console.log('Connected to the database.');
});



function get_playlists(db){
    let sql = `SELECT DISTINCT Name name FROM playlists
               ORDER BY name`;

    let data = []
    db.all(sql, [], (err, rows) =&gt; {
      if (err) {
        throw err;
      }
      rows.forEach((row) =&gt; {
        console.log(row.name);
        data.push(row.name);
      });
      return data
    });
}

result = get_playlists(db)
console.log('...result', result);
db.close();
</code></pre>
