I'm passing data to render template:
res.render 'index', {data: ['a', 'b']}, function(err, html) {
});
in the template, I'd like to render the array ['a', 'b'] as an array in javascript:
script(type='text/javascript').
var arr = #{data};
but they are rendered as [a, b], an array of variables, what I want is variable names: ['a', 'b'].
Thanks
First you need to JSON.stringify the data property object.
...
data: JSON.stringify(['a', 'b'])
...
Then in your Jade Template use !{}.
var arr = !{data}; // ["a","b"];