loop object in react code example

Example 1: react js iterate object

<div className="iterate-object">
{
	<ul>
  		{Object.keys(OBJECTHERE).map(function(keyName, keyIndex) {
    		return (
      			<li key={keyName}>
					{keyName}
                    {console.log(OBJECTHERE[keyName])}
          		</li>
    		)
		})}
	</ul>
}
</div>

Example 2: react for loop in render

render: function() {
  const elements = ['one', 'two', 'three'];
  return (
    <ul>
      {elements.map((value, index) => {
        return <li key={index}>{value}</li>
      })}
    </ul>
  )
}

Example 3: react render for loop

// for loop workaround in react render
[...Array(n)].map((_, index) => <span key={index}>element {index}</span>)