getreact component with specific key number code example

Example 1: how to get property names from object using map method react

const arrayvals = [
   { Number: 1, newNumber: "1", name: "FB" },
    { Number: 3, newNumber: "2", name: "FB" },
     { Number: 7, newNumber: "5", name: "GK" },
      { Number: 8, newNumber: "4", name: "FW" }
]



function App() {
  return (
    <div className="App">
      <h1>Mapping object keys in react and returning child properties
</h1>
    {Object.entries(arrayvals).map((arr)=>{

        return <div>Number is : {arr[1].Number}  || NewNumber is : {arr[1].newNumber} ||  and Value is : {arr[1].name}</div>
    })}
    </div>
  );
}

Example 2: react component key prop

function ListItem(props) {
  // Correct! There is no need to specify the key here:  return <li>{props.value}</li>;}

function NumberList(props) {
  const numbers = props.numbers;
  const listItems = numbers.map((number) =>
    // Correct! Key should be specified inside the array.    <ListItem key={number.toString()} value={number} />  );
  return (
    <ul>
      {listItems}
    </ul>
  );
}

const numbers = [1, 2, 3, 4, 5];
ReactDOM.render(
  <NumberList numbers={numbers} />,
  document.getElementById('root')
);