map function in react

Code Example - map function in react

                
                        function NameList() {
	const names = ['Bruce', 'Clark', 'Diana']
    return (
    	<div>
      {names.map(name => <h2>{name}</h2>)}
      	</div>
    )
}
                    
                
 

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>
  )
}
                            
                        
 

react for loop

                        
                                <tbody>
  {[...Array(10)].map((x, i) =>
    <ObjectRow key={i} />
  )}
</tbody>
                            
                        
 

react loop through array

                        
                                this.items = this.state.cart.map((item, key) =>    <li key={item.id}>{item.name}</li>);