1

I have an array called courses[], in this array there are multiple objects. Each object represents a single course.

I'm trying to render out all my object properties for each course. With my current way of doing this I can console.log all my object properties but I'm unsure how I would render it out to the DOM. I tried the following but doesn't render out anything:

<div className="courses">
    {
      courses.map(course =>
        Object.keys(course).forEach((val, key) => {
          return <div key={key}>{val}</div>;
        })
      )
    }
</div>

What am I missing here?

1 Answer 1

4

A forEach does not return anything. Instead use map and it should work.

e.g.

Object.keys(course).map(...)
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.