I have a variable on the server side of Node.js that is an object. I can verify this with console.log(typeof(value));
and i get object
.
When I do a console.log(value);
I get
[ 'bla_bla_1',
'bla_bla_2',
'bla_bla_3',
]
Then I pass the variable to the client with Express: res.render('target.ejs', {data:value});
and the ejs file parses it with var value = '<%= data %>';
I want to know if it is an object or an array, in order to figure out how to handle it on the client side.
I wrote a little script to test it:
if (typeof(value) === 'object') {console.log("IT'S AN OBJECT");}
else {console.log("IT'S NOT AN OBJECT");}
if ( Array.isArray(value) ) {console.log("IT'S AN ARRAY");}
else {console.log("IT'S NOT AN ARRAY");}
What I get back is this in the console of the browser:
IT'S NOT AN OBJECT
IT'S NOT AN ARRAY