I am using node.js express 4
at my index.js routes file I have this
router.get('/', function(req, res, next) { res.render('index', {items: myItemsdocs}); }}; at my index.hbs view I'm trying to use items as a javascript variable
var jsItems = items; var name1 = jsItems[Object.keys(jsItems)[0]].itemName; alert(name1); but nothing happens .. how can I use items object I have in the client side javascript ?
my template engine is express-handlebars
var jsItems = {{items}};var jsItems = "{{items}}";If it's an array or anything like that, you need to serialize it, then parse it back into an object.