react map array of objects 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: how to map array of objects in react

[{
    name: 'Sam',
    email: '[email protected]'
 },
 {
    name: 'Ash',
    email: '[email protected]'
 }
].map( ( {name, email} ) => {
    return <p key={email}>{name} - {email}</p>
})

Example 4: javascript create array of objects with map

var arr = [{
  id: 1,
  name: 'bill'
}, {
  id: 2,
  name: 'ted'
}]

var result = arr.map(person => ({ value: person.id, text: person.name }));
console.log(result)

Example 5: how map work in react

{this.state.data.map((person) => <TableRow key = {shortid.generate()} data = {person} />)}

Example 6: react native map array of objects

var tmp_array = [
 { headline: "Test", text: "Test text", send_at: "test date" }
];