Reactjs

How to render an array of objects in React?

Render an array of objects in React

Views

Hello, welcome to therichpost.com. In this post, I will tell you, How to render an array of objects in React?Reactjs is a Javascript Library to build user interface. Now I am also learning Reactjs these day because of my passion to learn new things.

In this post, we will render an array data.  We will use map is used to convert an array with items of type “string” to an array of React.DOM.li elements.

 

Here is working and tested code and I have added this in index.js file:
import React from 'react';
import ReactDOM from 'react-dom';

class Hello extends React.Component{
  constructor()
  {
    super();
    //declare custom data array of object
    this.state = {
      names:['ajay', 'alisha', 'jas']
    }
  }
  render()
  {
    return (
      <ul>
      {
        //map array data
        this.state.names.map(function(name){
            return <li key={name}>{name}</li>
        })
      }
      </ul>
    )
  }
}

ReactDOM.render(<Hello />, document.getElementById('root'));

 map-array-data-reactjs

if you have any query related to this post then please comment below.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Positive SSL