map array react component code example

Example 1: react map

{array.map((item)=>{
  return (
    <div key={item.id}>I am one Object in the Array {item}</div>
  )
})}

Example 2: map function in react

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

Example 3: react map

const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map((number) => number * 2);console.log(doubled);

Example 4: jsx map with index

materials.map((material,index) => console.log(index +" = " + material + " = " + materials[index]));