4

I am trying to render an objects key and value, however it just doesn't seem to work.

I have managed to display it in the console, but not the actual dom. I am iterating through the object which has multiple entries.

What do I need to do to actually print out the values?

{attributes.map(items => {                                
                            {Object.keys(items).map((key) => {
                                console.log(key, items[key]);
                            })}
                        })}

1 Answer 1

9

Like this:

{attributes.map((items, index) => {
  return (
    <ul key={index}>
    {Object.keys(items).map((key) => {
      return (
        <li key={key + index}>{key}:{items[key]}</li>
      )
    })}
    </ul>
  )
})}
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.