You can do it in two ways:

First:

render() {
    const data =[{"name":"test1"},{"name":"test2"}];
    const listItems = data.map((d) => <li key={d.name}>{d.name}</li>);

    return (
      <div>
      {listItems }
      </div>
    );
  }

Second: Directly write the map function in the return

render() {
    const data =[{"name":"test1"},{"name":"test2"}];
    return (
      <div>
      {data.map(function(d, idx){
         return (<li key={idx}>{d.name}</li>)
       })}
      </div>
    );
  }
Answer from Shubham Khatri on Stack Overflow
Top answer
1 of 7
189

You can do it in two ways:

First:

render() {
    const data =[{"name":"test1"},{"name":"test2"}];
    const listItems = data.map((d) => <li key={d.name}>{d.name}</li>);

    return (
      <div>
      {listItems }
      </div>
    );
  }

Second: Directly write the map function in the return

render() {
    const data =[{"name":"test1"},{"name":"test2"}];
    return (
      <div>
      {data.map(function(d, idx){
         return (<li key={idx}>{d.name}</li>)
       })}
      </div>
    );
  }
2 of 7
21

https://facebook.github.io/react/docs/jsx-in-depth.html#javascript-expressions

You can pass any JavaScript expression as children, by enclosing it within {}. For example, these expressions are equivalent:

<MyComponent>foo</MyComponent>

<MyComponent>{'foo'}</MyComponent>

This is often useful for rendering a list of JSX expressions of arbitrary length. For example, this renders an HTML list:

function Item(props) {
  return <li>{props.message}</li>;
}

function TodoList() {
  const todos = ['finish doc', 'submit pr', 'nag dan to review'];
  return (
    <ul>
      {todos.map((message) => <Item key={message} message={message} />)}
    </ul>
  );
}

class First extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      data: [{name: 'bob'}, {name: 'chris'}],
    };
  }
  
  render() {
    return (
      <ul>
        {this.state.data.map(d => <li key={d.name}>{d.name}</li>)}
      </ul>
    );
  }
}

ReactDOM.render(
  <First />,
  document.getElementById('root')
);
  
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root"></div>

🌐
GUVI
guvi.in › blog › programming languages › how to render an array of objects in react? [in 3 easy steps]
How to Render an Array of Objects in React? [in 3 easy steps]
October 21, 2025 - Also Read: How to use Props in React. To render an array of objects/items in React, we loop through the array using the .map() method and return a single item.
Discussions

How do i render an array of object in react
Hi, I am new to react, and I would like to know how I can render an array of object(questions & answers). Here is what I have done so far: class App extends React. Component { constructor(props){ super(props); this.state=({ question : [], }) } questions = [ { question: "Who is the strongest?", ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
March 23, 2019
Rendering React Components from Array of Objects
The array after mapping can be directly returned instead. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... I’m Jody, the Chief Product and Technology Officer at Stack Overflow. Let’s... ... 0 How can I render several objects of the same class in React... More on stackoverflow.com
🌐 stackoverflow.com
Render array of objects inside array of objects
Is it just the owners not being displayed or Data in whole? More on reddit.com
🌐 r/reactjs
4
1
December 4, 2024
How do i render an array of object in react
Hi, I am new to react, and I would like to know how I can render an array of object(questions & answers). Here is what I have done so far: class App extends React. Component { constructor(props){ super(props); this.state=({ question : [], }) } questions = [ { question: "Who is the strongest?", ... More on freecodecamp.org
🌐 freecodecamp.org
0
0
March 24, 2019
People also ask

How do you render multiple objects in React?
You can use the Array's map functionality to render multiple elements in React. Simply map all your objects into React fragments, so that your Function component can make use of it. But don't forget to set a unique key prop!
🌐
guvi.in
guvi.in › blog › programming languages › how to render an array of objects in react? [in 3 easy steps]
How to Render an Array of Objects in React? [in 3 easy steps]
How do you set an array of objects in state in React JS?

To set an array of objects in the state of a React component, you can use the 'useState' hook. So to do this, first, import 'useState' from 'react'. Then, declare a state variable using useState and initialize it with your array of objects. To update the state, use the setter function provided by the useState hook. And voila, now you can easily manage and modify the array of objects within your component's state.
🌐
guvi.in
guvi.in › blog › programming languages › how to render an array of objects in react? [in 3 easy steps]
How to Render an Array of Objects in React? [in 3 easy steps]
How do you iterate an array of objects in React JS?

To iterate through an array of objects in ReactJS, you must use the mao() method. It creates a new array by applying a provided function to each element of the original array. Within the function, you can access and render each object's properties as and when needed, effectively iterating through and rendering them in your React component.
🌐
guvi.in
guvi.in › blog › programming languages › how to render an array of objects in react? [in 3 easy steps]
How to Render an Array of Objects in React? [in 3 easy steps]
🌐
React
react.dev › learn › rendering-lists
Rendering Lists – React
On this page, you’ll use filter() and map() with React to filter and transform your array of data into an array of components. How to render components from an array using JavaScript’s map()
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › how-to-render-an-array-of-objects-in-reactjs
How To Render An Array Of Objects In ReactJS? - GeeksforGeeks
July 23, 2025 - The most common and recommended way to render an array of objects in React is by using the Array.map method to iterate through the array.
🌐
freeCodeCamp
forum.freecodecamp.org › t › how-do-i-render-an-array-of-object-in-react › 266845
How do i render an array of object in react - The freeCodeCamp Forum
March 23, 2019 - Hi, I am new to react, and I would like to know how I can render an array of object(questions & answers). Here is what I have done so far: class App extends React. Component { constructor(props){ super(props); this.state=({ question : [], }) } questions = [ { question: "Who is the strongest?", answers: { a: "Superman", b: "The Terminator", c: "Waluigi, obviously" }, ]; handleQuestion(){ this.setState({ question: questions }) } render(...
Top answer
1 of 6
197

You can map the list of stations to ReactElements.

With React >= 16, it is possible to return multiple elements from the same component without needing an extra html element wrapper. Since 16.2, there is a new syntax <> to create fragments. If this does not work or is not supported by your IDE, you can use <React.Fragment> instead. Between 16.0 and 16.2, you can use a very simple polyfill for fragments.

Try the following

// Modern syntax >= React 16.2.0
const Test = ({stations}) => (
  <>
    {stations.map(station => (
      <div key={station.call} className='station'>{station.call}</div>
    ))}
  </>
); 

// Modern syntax < React 16.2.0
// You need to wrap in an extra element like div here

const Test = ({stations}) => (
  <div>
    {stations.map(station => (
      <div className="station" key={station.call}>{station.call}</div>
    ))}
  </div>
); 

// old syntax
var Test = React.createClass({
    render: function() {
        var stationComponents = this.props.stations.map(function(station) {
            return <div className="station" key={station.call}>{station.call}</div>;
        });
        return <div>{stationComponents}</div>;
    }
});
 
var stations = [
  {call:'station one',frequency:'000'},
  {call:'station two',frequency:'001'}
]; 

ReactDOM.render(
  <div>
    <Test stations={stations} />
  </div>,
  document.getElementById('container')
);

Don't forget the key attribute!

https://jsfiddle.net/69z2wepo/14377/

2 of 6
61

I have an answer that might be a bit less confusing for newbies like myself. You can just use map within the components render method.

render () {
   return (
       <div>
           {stations.map(station => <div key={station}> {station} </div>)} 
       </div>
   );
}
Find elsewhere
🌐
Atomizedobjects
atomizedobjects.com › blog › react › how-to-render-an-array-of-objects-with-map-in-react
How to render an array of objects with Array.map in React | Atomized Objects
To render an array of objects in react with JSX we need to use Array.map() to transform the object into something react can make use of because you cannot directly render an object into React.
🌐
Codemzy
codemzy.com › blog › react-render-array-of-objects
How to render an array of objects in ReactJS - Codemzy's Blog
August 31, 2022 - If you try to render an array of objects in ReactJS, you might run into errors. Because ReactJS can't render the object. But you can loop over the array and turn it into something ReactJS can render, like a string or JSX.
🌐
KindaCode
kindacode.com › article › react-rendering-an-array-of-objects
React: How to Render an Array of Objects (Full Example) - KindaCode
March 3, 2023 - In React, the most popular way to render an array of objects is to use the Array.map() method.
🌐
Atomizedobjects
atomizedobjects.com › blog › react › how-to-render-an-array-of-components-in-react
How to render an array of components in React | Atomized Objects
To render an array of components in React you simply need to pass the array into JSX by wrapping it in curly braces, just be sure that your components each have a unique key prop because React will use this when rendering it to avoid bugs. Here is an example of rendering an array of objects ...
🌐
Shameem
shameem.me › home › how to render an array of objects in react?
How to Render an Array of Objects in React? - Shameem
March 31, 2023 - We use the map() method to iterate over each employee object in the array and create a new array of React elements. In the map() method, we create a new <div> element for each employee and set the key prop to a unique identifier for each employee.
🌐
DigitalOcean
digitalocean.com › community › conceptual-articles › understanding-how-to-render-arrays-in-react
Understanding How To Render Arrays in React | DigitalOcean
July 27, 2020 - The <ol> component will create an ordered list of the items: function ReptileList() { const reptiles = ["alligator", "snake", "lizard"]; return ( <ol> {reptiles.map((reptile) => ( <li>{reptile}</li> ))} </ol> ); } However, if you look at the console, you will see a warning that each child in an array or iterator should have a unique key. The warning appears because when you attempt to render a collection inside a component, you must add a key. In React, a unique key is used to determine which of the components in a collection needs to be re-rendered.
🌐
Reddit
reddit.com › r/reactjs › render array of objects inside array of objects
r/reactjs on Reddit: Render array of objects inside array of objects
December 4, 2024 -

Good morning everyone!

I have problem with React/TypeScript. Basically, i have a response from API containing this structure:

{

name: "",

year: 2024,

cars: [{

name: "Chevrolet Malibu",

year: 1967,

licencePlate: "V9-AHD",

owners: [{

name: "John Caxias",

phone: "+1 (555) 999-9999"

}, {

name: "Denise Owen",

phone: "+1 (555) 999-9999"

}]
}]
}

But, React/TypeScript, for one reason who i not understand, update the state and not renderize "owners", even have on state. Why this?

import React, { useState, useEffect } from 'react';

interface Car {

name: string;

year: number;

licencePlate: string;

owners: {

name: string;

phone: string;

}[];

}

interface Data {

name: string;

year: number;

cars: Car[];

}

const MyComponent: React.FC = () => {

const [data, setData] = useState<Data | null>(null);

useEffect(() => {

const fetchData = async () => {

try {

const response = await fetch('/api/data');

const data: Data = await response.json();

setData(data);

} catch (error) {

console.error('Error fetching data:', error);

}

};

fetchData();

}, []);

if (!data) {

return <div>Loading...</div>;

}

return (

<div>

<h1>{data.name} - {data.year}</h1>

<ul>

{data.cars.map((car) => (

<li key={car.licencePlate}>

<h3>{car.name} - {car.year}</h3>

<p>Licence Plate: {car.licencePlate}</p>

<h4>Owners:</h4>

<ul>

{car.owners.map((owner) => (

<li key={owner.name}>

{owner.name} - {owner.phone}

</li>

))}

</ul>

</li>

))}

</ul>

</div>

);

};

export default MyComponent;

🌐
DEV Community
dev.to › 04anilr › how-to-render-an-array-of-objects-in-reactjs--5d48
How to render an array of objects in ReactJS ? - DEV Community
April 3, 2024 - Example: In this example, we will map an Array of objects containing student Marks into a Table. // App.js import React from "react"; import Table from "react-bootstrap/Table"; import "bootstrap/dist/css/bootstrap.min.css"; import "./App.css"; // Render a table function RenderingArrayOfObjects() { const data = [ { Name: "Nikita", Marks: "98", Phone: "123", }, { Name: "Pratiksha", Marks: "96", Phone: "127", }, { Name: "Muskan", Marks: "97", Phone: "163", }, { Name: "Nishi", Marks: "95", Phone: "193", }, { Name: "Himanshu", Marks: "78", Phone: "120", }, ]; // Render rows/items const tableRows =
🌐
TutorialsPoint
tutorialspoint.com › how-to-render-an-array-of-objects-in-reactjs
How to render an array of objects in ReactJS?
It is impossible to render components using only filter() without map() because filter() only modifies the array but does not render elements itself. import React from "react"; const UserList = () => { const users = [ { id: 1, name: "Alice", age: 25, active: true }, { id: 2, name: "Bob", age: 30, active: false }, { id: 3, name: "Charlie", age: 35, active: true }, ]; return ( <div> {users .filter((user) => user.active) .map((user) => ( <div key={user.id}> <p>{user.name} </p> <p>Age: {user.age} </p> <p>Status: {user.active ?
Top answer
1 of 3
2

Here you need to move key property:

board.push(<div key={i}><Row /></div>);

Because key should be in the outside element of each element in array

2 of 3
0

The key prop should be on the first element of the iteration which is the div element:

board.push(<div key={i}><Row /></div>);

Also note that this row for( let i=props.key*3;i<(props.key+3);i++) might not work for you as there is not more key prop.

You can change it to: for( let i=0;i<3;i++)

Notice that it is an Anti-Pattern to use index as a key.

a key is the only thing React uses to identify DOM elements. What happens if you push an item to the list or remove something in the middle? If the key is same as before React assumes that the DOM element represents the same component as before. But that is no longer true.

Took from This medium - Index as a key is an anti-pattern

EDIT:

Added a sample code that should run for you.

Notice I've removed the Row component as it seem redundant.

I didn't understood why you need two for loops? Do you need 9 inputs or 3 inputs?

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';

function Square(props) {
  return (<input type='text' id={props.key} value={props.value}></input>);
}

class Box extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      squares: Array(9).fill(null),
      xIsNext: true,
    };
  }
  render() {
    let board = [];
    for (let i = 0; i < 3; i++) {
      const key = `${i}row`;
      board.push(<Square key={key} value={i} />);
      console.log(i)
    }
    return (board);
  }
}
ReactDOM.render(
  <Box />,
  document.getElementById('root')
);
🌐
YouTube
youtube.com › watch
ReactJS Tutorial 14 : Rendering Array Of Objects In React - YouTube
In this lecture we will learn how to render array of objects in React.Entire React Playlist: https://www.youtube.com/watch?v=MHn66JJH5zs&list=PLSsAz5wf2lkKm0...
Published   August 31, 2023
🌐
The Web Dev
thewebdev.info › home › how to render an array of objects in react?
How to render an array of objects in React? - The Web Dev
June 2, 2022 - We set the key prop to a unique value for each entry so that React can identify each item being rendered. To render an array of objects in React, we can use the array map method.
Top answer
1 of 10
21

Have you consider using the new React Fragments? (in v16)

This would be the simplest solution as it would by pass the whole array/key issue.

If you need to pass key, then I'd suggest to simply require the components to have the keys. This is how React works, so I wouldn't suggest you to hide this behavior behind an interface that might not be predictable.

If you really need to do this, then you can use React.cloneElement to clone the element and inject new properties:

React.cloneElement(element, { key: 'foo' });
2 of 10
15

If you’re always going to want to render all the components in your components file then you’re probably better off wrapping them in a React.Fragments tag.

Best practise is just to export this as a simple function that returns the components rather than as a constant.

So...

const Components = props => {
  return (
    <React.Fragment>

      <ComponentOne/>
      <ComponentTwo/>

    </React.Fragment>
  )
}

export default Components

That allows you to put multiple components next to each other without a DOM element containing them.

You should then just be able to render that by using it as a normal component and it’ll render all of them, so just import it then...

<Components />

Otherwise, if you want to treat them like an array, you have a function for free on the React object you’ve imported...

React.Children.toArray(arrayOfComponents)

You pass it an array of components (like in your original question) and it allows you to sort and slice it if you need to then you should be able to just drop it in the return of your render function