1

I have a javascript object that I'm trying to render in React. I've only used arrays with .map before and it doesn't seem to want to work with an object. What's the best way to iterate over an object that's being passed through this.props?

I get the following console error when trying to use .map on this object:

data.map is not a function

Thanks!

render: function() {    

  let data = this.props.data

  let nameList = data.map(function(details){
    return (
      <div>
        <h1>{details.name}</h1>
      </div>
    )
  });

  return (
    <div>{nameList}</div>
  )
}
dace
  • 5,819
  • 13
  • 44
  • 74

0 Answers0