0👍
✅
You need to use unescaped string interpolation and a stringify to turn your pug variable into a client-side browser variable:
var arrayForChart = !{JSON.stringify(arrayInPug)};
If the variable in express/pug is ['a', 'b', 'c']
then this will output:
var arrayForChart = ['a', 'b', 'c'];
Without the stringify you’ll get something like this which will just throw an error in the browser as it’s not valid JavaScript:
var arrayForChart = [Object object];
Source:stackexchange.com