adding list items in react 1

adding list items in react

const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>  
  • {number}
  • ); ReactDOM.render(
      {listItems}
    , document.getElementById('root') );

    Here is what the above code is Doing:
    1. We pass an array of numbers to the map() function.
    2. The map() function loops through each number in the array.
    3. For each iteration, the map() function will return a

  • element containing the number.
    4. Finally, the map() function returns a new array containing all the

  • elements.
    5. We pass this new array to the ReactDOM.render() function.

  • Similar Posts