Passing an object to client in node/express + ejs?
ejs, express, node.js
Solution
That is the expected behavior. Your template engine is trying to create a string from your object which leads to [Object object]. If you really want to pass data like that I think you did the correct thing by stringifying the object.
Problem
I have a pretty large object that I need to pass to a function in a client script. I have tried using JSON.stringify, but have run into a few issues with this approach - mostly performance related. Is it possible to do something like this in ejs? ``` app.get('/load', function(req, res) { var data = { layout:'interview/load', locals: { interview: '', data: someLargeObj } }; res.render('load', data); }); ``` And in my client script, I would pass this object to a function like so ``` <script type="text/javascript"> load(<%- data %>); // load is a function in a client script </script> ``` When I try this I get either ``` <script type="text/javascript"> load(); </script> ``` or ``` <script type="text/javascript"> load([Object object]); </script> ```