Search code examples
javascriptpug

Use an array passed by express in plain javascript


I have this Javascript function in my index.pug file:

script(type='text/javascript').
 $(document).ready(function() {
    let chart = document.querySelectorAll('canvas');
    let lineChart = chart[0].chart;
    let pieChart = chart[1].chart;
    
    //TODO: Import Backend Features for usage (Banquery).
    // chart.data.datasets[0].data[2] = 20000;

    lineChart.update();
    pieChart.update();
 })

And in server.js (An express app) this code to give an array of months:

app.get("/", async (req, res) => {
  res.render("index", {
    month: month
  });
});

My question is: How can i interact with this month array in the pug file for usage?


Solution

  • Thanks to @symlink for giving me the link to the Getting Started Page i fixed my code:

    let month = [#{month}];
    

    with this i was able to get my array to work in the frontend. :)