I don't know what the problem is so, i know the title doesnot describes anything my appologies for that. Here is the problem I am facing. I am currently working in a MERN app.
I have a route in express where i request for some data from the database from two tables.
playlist.post("/getplaylistSongs", (req, res) => {
  const { cookie } = req.body;
  const sql = "SELECT * FROM playlist WHERE user_id = ?";
  dbCon.query(sql, [cookie], (err, result) => {
    if (err) {
      res.status(400).json({
        message: "failed to get playlist details ",
      });
    } else {
      let playlistSongs = [];
      result.forEach((element, index) => {
        const audio_id = element.audio_id;
        dbCon.query(
          "SELECT * FROM audios where video_id = ?",
          [audio_id],
          (err, song) => {
            if (err) {
              res.status(400).json({
                message: "failed to get music",
              });
            } else {
              playlistSongs.push(song);
            }
          });
      });
     console.log(playlistSongs); 
      res.status(200).json({
        playlist: playlistSongs,
      });
    }
  });
});
but the problem here is however i try to do it i always get the playlistSongs as an empty array.
thank you. comment for correcting the question.
EDIT : Now i know the problem is realted to execution of the javascript.
