Think of it like you're just calling JavaScript functions. You can't use a for loop where the arguments to a function call would go:

return tbody(
    for (let i = 0; i < numrows; i++) {
        ObjectRow()
    } 
)

See how the function tbody is being passed a for loop as an argument – leading to a syntax error.

But you can make an array, and then pass that in as an argument:

const rows = [];
for (let i = 0; i < numrows; i++) {
    rows.push(ObjectRow());
}
return tbody(rows);

You can basically use the same structure when working with JSX:

const rows = [];
for (let i = 0; i < numrows; i++) {
    // note: we are adding a key prop here to allow react to uniquely identify each
    // element in this array. see: https://reactjs.org/docs/lists-and-keys.html
    rows.push(<ObjectRow key={i} />);
}
return <tbody>{rows}</tbody>;

Incidentally, my JavaScript example is almost exactly what that example of JSX transforms into. Play around with Babel REPL to get a feel for how JSX works.

Answer from Sophie Alpert on Stack Overflow
🌐
Sentry
sentry.io › sentry answers › react › how do you loop inside react jsx?
How do you loop inside React JSX? | Sentry
You can loop over an array and ... } export default App; You can use the map() method on an array to loop through the elements and create components, or generate JSX, inside the return block....
Discussions

Loop through Array within Object React
Hi, I’m very new to React, I’m working on a project where I’m fetching data from an API then display is on a table. there is a array within the object returned and the indexes are mixed up i.e value in array [0] is ‘BMW’ and in a different object returned array [0] is ‘Grey’. ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
August 27, 2022
Can I use a for loop with JSX? To render something 3 times?
[...Array(3).keys()].map(key =>

Hi

) More on reddit.com
🌐 r/reactjs
23
2
August 31, 2021
Using anything rather than .map to render lists in JSX?
I've used for loops cos state held an array, even experimented with reduce to create a single consolidated code block of lists, but nothing else is as simple and effective as using map. More on reddit.com
🌐 r/reactjs
45
0
February 7, 2024
How to re-render a map loop in React?
It looks like there's two problems: You're mutating the existing data array by calling Array.splice() It also doesn't look like that data array is in React state, and you're not calling any form of setState(). React requires that you call some form of setState() to cause a re-render. I'd recommend going through the React beta docs to understand how to use state in components and update it: https://beta.reactjs.org/learn/state-a-components-memory https://beta.reactjs.org/learn/updating-arrays-in-state You might also want to read my post A (Mostly) Complete Guide to React Rendering Behavior to better understand how React rendering works. More on reddit.com
🌐 r/reactjs
4
1
October 27, 2022
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
Iterate Through a JSON Response in JSX Render for React | Pluralsight
September 25, 2020 - Next, iterate over the data using the map() or forEach() methods or using loops. The map() method is the most commonly used function to iterate over an array of data in JSX. You can attach the map() method to the array and pass a callback function ...
🌐
DhiWise
dhiwise.com › post › mastering-react-looping-through-array-a-comprehensive-guide
Understanding React Looping Through Array
January 10, 2024 - Instead, React leverages the power of the JavaScript map method to iterate over array data. The map function is a concise and expressive way to transform arrays into React JSX elements.
🌐
Telerik
telerik.com › blogs › beginners-guide-loops-in-react-jsx
A Beginner’s Guide to Loops in React JSX
August 18, 2022 - // JSX example return ( <div> <button onClick={onClickHandler}>Submit</button> </div> ) // The above will be converted to something like this return React.createElement( "div", {}, React.createElement( "button", { onClick: e => {} }, "Submit" ) ); You can read more about it on the React website. When I first started with React, I realized quite early that I did not know how to loop through an array and render a list of items.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Loop through Array within Object React - JavaScript
August 27, 2022 - Hi, I’m very new to React, I’m working on a project where I’m fetching data from an API then display is on a table. there is a array within the object returned and the indexes are mixed up i.e value in array [0] is ‘BMW’ and in a different object returned array [0] is ‘Grey’. therefore i would like to loop through this array the give a condition as to what data i want to display. is this possible and if so how? the image attached is how I’m rendering my current display but the data output is wr...
Find elsewhere
🌐
Squash
squash.io › how-to-use-loop-inside-react-jsx
How To Use Loop Inside React JSX - Squash Labs
Inside the JSX code, we use the map() function to iterate over each item in the items array. For each item, we render an <li> element with the item's value as the content. The key prop is used to uniquely identify each list item.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › loop-inside-react-jsx
Loop Inside React JSX - GeeksforGeeks
August 5, 2025 - When working with React, you often need to render lists of items dynamically. JavaScript's map function provides a convenient way to loop through arrays and generate JSX elements for each item.
🌐
Upmostly
upmostly.com › home › tutorials › how to for loop in react (with examples)
How to Use For Loop in React (with Code Examples)
October 28, 2021 - Again, because we’re using JSX, we can have our JavaScript Map function output HTML. In our case, we loop through the names array and output a set of <li> tags for each element in the array, thus creating a list:
🌐
Reddit
reddit.com › r/reactjs › can i use a for loop with jsx? to render something 3 times?
r/reactjs on Reddit: Can I use a for loop with JSX? To render something 3 times?
August 31, 2021 -
let sampleOutput =()=>{
  return
    for(let i=0;i<3;i++){<p>hi</p>}  
}


trying to display hi 3 times inside

return()

in my component. I know how to .map or .forEach for objects and arrays but what if my store or variable is just a number, I assume forloop doesnt work?

🌐
Thinkster
thinkster.io › tutorials › iterating-and-rendering-loops-in-react
Iterating & Rendering with Loops in React components - Thinkster
For those of you who are Javascript experts, you’ll know that we can use Javascript’s map method to quickly iterate over our array and create a new one with our desired values!
🌐
CoreUI
coreui.io › blog › how-to-loop-inside-react-jsx
How to loop inside React JSX · CoreUI
September 27, 2024 - However, normal JavaScript constructs, like for loops, aren’t directly supported within JSX because they are statements, not expressions. Therefore, React developers need to rely on function calls and methods like map to achieve dynamic rendering. The most common and recommended way to render lists in React is by using the map method. The map function creates a new array by calling a provided function on every element in the calling array.
🌐
SheCodes
shecodes.io › athena › 10518-how-to-loop-an-array-in-react-and-render-the-results
[React] - How to Loop an Array in React and Render the | SheCodes
Learn how to loop through an array in React and render it on the page, including a key for each element, using the .map() function.
🌐
DhiWise
dhiwise.com › post › mastering-react-iterate-over-object-a-comprehensive-guide
The Ultimate Guide to React Iterate Over Object
September 5, 2024 - This pattern is directly applicable to React when rendering lists of components based on an array of data. Looping through objects in React requires converting the object into an iterable format, such as an array of keys, values, or entries.
🌐
Bobby Hadz
bobbyhadz.com › blog › react-loop-through-array-of-objects
Loop through an Array of Objects in React | bobbyhadz
The last step is to render the array of results. If you need to filter an array of objects in React, click on the following article. You can also loop through an array of objects using the for...of loop.
🌐
Stack Abuse
stackabuse.com › how-to-loop-in-react-jsx
How to Loop in React JSX
June 15, 2022 - Like in our todos array example, we can specify each todo id as the key: { todos.map((todo) => ( <div key={todo.id}> <p key={todo.text}> {todo.text} - {todo.status} </p> </div> )); } If the item you’re trying to loop through does not have a unique element, such as a unique id - it is a common convention to use the index returned by the map() function for each iterated element instead, ensuring unique element identification without changing your domain model:
🌐
React
react.tips › how-to-loop-inside-jsx-in-react-16
How To Loop Inside JSX Syntax In React 16 - React Tips
We can add JavaScript expressions inside of JSX syntax. JSX syntax itself is an expression too. In that JavaScript expression we're looping through an array called MONTHS and for each item in that array we call this.createMonthElement method and pass an array item as an argument to it.
🌐
Plain English
plainenglish.io › blog › how-to-loop-through-arrays-in-react
How to loop through arrays in React
The map() method creates a new array with the results of calling a provided function on every element in the calling array. So the map function was introduced to JavaScript in ES2015.
🌐
Code With Vinod
codewithvinod.com › how-to-loop-and-display-an-object-in-react-jsx
How To Loop And Display An Object In React Jsx
August 1, 2025 - To loop through and display an object in JSX, you can use the Object.keys() or Object.entries() method along with the map function. Here’s an example using Object.keys(): In this example, Object.keys(person) returns an array of the object’s ...