🌐
React
react.dev › learn › rendering-lists
Rendering Lists – React
Here’s a short example of how to generate a list of items from an array: ... const people = [ 'Creola Katherine Johnson: mathematician', 'Mario José Molina-Pasquel Henríquez: chemist', 'Mohammad Abdus Salam: physicist', 'Percy Lavon Julian: chemist', 'Subrahmanyan Chandrasekhar: astrophysicist' ]; export default function List() { const listItems = people.map(person => <li>{person}</li> ); return <ul>{listItems}</ul>; }
🌐
React
legacy.reactjs.org › docs › lists-and-keys.html
Lists and Keys – React
We can refactor the previous example into a component that accepts an array of numbers and outputs a list of elements. function NumberList(props) { const numbers = props.numbers; const listItems = numbers.map((number) => <li>{number}</li> ); return ( <ul>{listItems}</ul> ); } const numbers = [1, 2, 3, 4, 5]; const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<NumberList numbers={numbers} />);
🌐
Medium
medium.com › @vipraaditya › mastering-array-manipulation-in-react-a-comprehensive-guide-5f6e1164c9d1
Mastering Array Manipulation in React: A Comprehensive Guide | by Aditya Narayan Tiwari | Medium
December 17, 2023 - Arrays are fundamental data structures ... lists of data is a common task. To harness the full power of React, developers need a solid understanding of array methods that facilitate efficient data manipulation. In this comprehensive guide, we’ll explore an array of array methods that are crucial for React development. To begin, let’s examine the concept of an array method. An array method refers to a function that can be ...
🌐
W3Schools
w3schools.com › react › react_es6_array_methods.asp
React ES6 Array Methods
The .map() method allows you to run a function on each item in the array, returning a new array as the result. In React, map() can be used to generate lists.
🌐
React Dev Station
reactdevstation.github.io › 2020 › 03 › 19 › essential-array-functions.html
Essential Array Functions | React Dev Station
March 19, 2020 - The most common array function in React eco-system, we often use to create JSX for the items in an array.
🌐
DEV Community
dev.to › jamesncox › array-methods-33ii
Array Methods - DEV Community
April 29, 2021 - If you are new to JavaScript and/or React, and maybe unsure what you need to know to get started. This post is Part II in a series called Essential JavaScript Building Blocks for React, and we will take a look at several array methods, what they do, and how we use them in React.
🌐
Medium
medium.com › byte-sized-react › component-arrays-in-react-a46e775fae7b
Lists and Arrays in React
September 12, 2017 - const App = props => { const quoteArray = props.quotes.map((quote) => { return ( <Quote text={quote.text} author={quote.author} /> ); }); return ( <div> <h2>Famous Quotes</h2> {quoteArray} </div> ); };App.propTypes = { quotes: React.PropTypes.array } Notice how we used the map function to generate our React element array and then used the curly braces to insert the quoteArray as a JavaScript expression in the App component.
🌐
W3Schools
w3schools.com › react › react_es6_array_map.asp
React ES6 Array map()
The map() method creates a new array with the results of calling a function for every array element. ... const fruitlist = ['apple', 'banana', 'cherry']; function MyList() { return ( <ul> {fruitlist.map(fruit => <li key={fruit}>{fruit}</li> ...
🌐
TutorialKart
tutorialkart.com › react › react-render-array-as-list
React - Render Array as List - Examples [3]
December 29, 2024 - Rendering arrays as lists: JavaScript ... as user data, tasks, or any other type of collection. React provides a simple and efficient way to iterate over arrays and render their content as list items using the map function....
Find elsewhere
🌐
Medium
medium.com › @shwetakoffficiall › display-list-of-items-from-array-in-react-7307e049429d
Display List of Items from Array in React | by Shweta K | Medium
June 10, 2024 - The key attribute is set to the current index to help React identify which items have changed, are added, or are removed. ... const items = ['apple', 'banana', 'oranges']; return ( <div> <h1>List of fruits</h1> <ul> {items.map((item, index) ...
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › reactjs-lists
React Lists - GeeksforGeeks
April 9, 2026 - In React, lists are used to render multiple elements dynamically from arrays or objects, making UI development efficient and reusable. The map() function helps iterate over data and return JSX for repeated elements.
🌐
React
react.dev › learn › updating-arrays-in-state
Updating Arrays in State – React
There are multiple ways to do this, but the easiest one is to use the ... array spread syntax: ... import { useState } from 'react'; let nextId = 0; export default function List() { const [name, setName] = useState(''); const [artists, setArtists] = useState([]); return ( <> <h1>Inspiring sculptors:</h1> <input value={name} onChange={e => setName(e.target.value)} /> <button onClick={() => { setArtists([ ...artists, { id: nextId++, name: name } ]); }}>Add</button> <ul> {artists.map(artist => ( <li key={artist.id}>{artist.name}</li> ))} </ul> </> ); }
🌐
Medium
medium.com › @nicsatiembre › top-5-most-used-array-methods-in-reactjs-792593b19533
Top 5 Most used Array Methods in ReactJS | by Nicole Satiembre | Medium
March 30, 2024 - This determines which item in the array we are currently dealing with. ... Used to reduce the elements of an array to a single value. It iterates over each element in the array and applies a callback function ...
🌐
JavaScript in Plain English
javascript.plainenglish.io › react-native-array-methods-d469b7f10447
A Guide to React Native Array Methods | by Selahattindemir | JavaScript in Plain English
December 21, 2021 - Let’s consider what an array method is. Simply put, React array methods are the methods that are available as array prototypes with the new version of JavaScript, by which we can navigate the array elements one by one with the help of a callback function and perform certain checks
🌐
Medium
raymondosy.medium.com › 5-must-know-array-methods-in-react-da531a02b0ef
5 must-know array methods in React | by Raymond Akalonu | Medium
December 11, 2019 - Simply put, an array method is a method that can be called on an array to perform an action on or with that array. Here are a few javascript array methods used in react. This array method takes in a function that will be called on each element in a given array and it returns a new set of an ...
🌐
Medium
medium.com › @pawan2505 › array-and-object-handling-in-reactjs-4a6dc3619d4f
Array and Object Handling in ReactJS | by PΛWΛN | Medium
November 17, 2024 - Keys must be unique for each item to help React identify changes. Avoid using array indexes as keys in production if the array is dynamic. These methods are essential for advanced data handling. ... const products = [ { name: "Apple", price: 10 }, { name: "Banana", price: 5 }, ]; const total = products.reduce((acc, product) => acc + product.price, 0); function App() { return <p>Total Price: {total}</p>; }
🌐
Stack Overflow
stackoverflow.com › questions › 53925423 › how-to-map-function-returning-array-in-react
How to map function returning array in react
December 26, 2018 - In example 1. I can map the function by passing it as prop to child component, however, what if i don't want to pass the function as a prop to a child component, how can i map the function in the main component itself as shown in example 2. ... class App extends React.Component { render() { return( <div> <Foo data={data()} /> </div> ) } } class Foo extends React.Component { render() { return ( <div> {this.props.data.map(item => { return ( <div>{item.id} {item.name}</div> ) })} </div> ) } } function data() { return ( [ {id: 1, name: "Jack"}, {id: 2, name: "Mark"}, {id: 3, name: "Mike"}, {id: 4, name: "Russell"} ] ) }
🌐
LinkedIn
linkedin.com › pulse › important-javascript-array-methods-know-before-learning
Important Javascript Array methods to know before learning React.js
July 4, 2023 - The map() method is used to create ... as the original array. Let’s look at an example: ... Array map methods are commonly used in React when rendering a list in React....
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>