0

I'm sending data over to my ejs files from my app.js file, and it looks like this:

{ _id: 2500, firstName: 'John', lastName: 'Doe', comments: [ { _id: 5555, title: "Hello", comment: "Hello, World" } ], __v: 0 }

When using a forEach loop, I can print out the entire document using <%= document %>.

I can print out the first and last name using <%= document.firstName %>.

When I use <%= document.comments %> it prints out the object, but I want it to print out only the "comment" string. I tried using <%= document.comments.comment %>, but nothing gets printed.

How do I access specific data in embedded objects?

1
  • Same way you access it normally; it's just JS. Commented Jun 14, 2019 at 4:11

1 Answer 1

1

As comments is an array you should try using <%= document.comments[0].comment %> for individual comment in comments array, <%= document.comments[0]%> for comments array

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.