The following ejs view outputs object for typeof().
<% if(typeof msg !== 'undefined'){ %>
<p><%- msg %> <%- typeof(user) %> </p>
<% } %>
This will output the entire object in the view.
<% if(typeof msg !== 'undefined'){ %>
<p><%- msg %> <%- user %> </p>
<% } %>
Like so,
{ _id: 6209571311be2a36444347fd, name: 'Joe', email: 'joe@e.com'}
However, when I try to access the values of user it results in either no output or an 'undefined' error.
For example, this code does not output the user.name value or throw any errors.
<% if(typeof msg !== 'undefined'){ %>
<p><%- msg %> <%- user.name %></p>
<% } %>
While this code causes the 'Cannot read property 'name' of undefined'.
<% if(typeof msg !== 'undefined'){ %>
<p><%- msg %> <%- user[0]['name'] %></p>
<% } %>
Can anyone tell me how to fix this. Thanks!