---
title: "How To Loop Inside JSX Syntax In React 16"
description: "Learn how to loop over arrays and render dynamic lists inside JSX in React 16 using Array.prototype.map, helper methods, and unique React key props."
url: "https://react.tips/how-to-loop-inside-jsx-in-react-16/"
category: "react"
published: "2019-01-30"
updated: "2026-12-01"
react_version: "16"
proficiency: "Beginner"
keywords: ["loop in JSX", "React Array.map", "React list rendering", "JSX", "React 16"]
author: "Artemij Fedosejev"
---

# How To Loop Inside JSX Syntax In React 16?

**Quick answer:** JSX accepts expressions, not `for` statements. To loop inside JSX in React 16, call `array.map(item => <ChildComponent key={item.id} item={item} />)` inside `{...}` curly braces, or extract the mapping into a helper method.

How do we generate React components by looping through an array of items inside JSX syntax?

## Demo Application Overview

Let's build a simple React application:

![React 16 application displaying a list of 12 months rendered by looping inside JSX](./images/app.png)

You can find the full source code in [this GitHub repository](https://github.com/fedosejev/how-to-loop-inside-jsx-in-react-16).

Our application is going to render a list of months. It will be made of two components: `App` and `Month`.

## Looping with `Array.prototype.map` in `App`

Let's create the `App` component first:

```jsx
import React, { Component } from "react";
import Month from "./Month";

const MONTHS = [
  {
    name: "January",
    number: 1
  },
  {
    name: "February",
    number: 2
  },
  {
    name: "March",
    number: 3
  },
  {
    name: "April",
    number: 4
  },
  {
    name: "May",
    number: 5
  },
  {
    name: "June",
    number: 6
  },
  {
    name: "July",
    number: 7
  },
  {
    name: "August",
    number: 8
  },
  {
    name: "September",
    number: 9
  },
  {
    name: "October",
    number: 10
  },
  {
    name: "November",
    number: 11
  },
  {
    name: "December",
    number: 12
  }
];

class App extends Component {
  createMonthElement = month => <Month month={month} key={month.number} />;

  render() {
    return (
      <div className="container">
        <div className="row">
          <div className="col-md-4 offset-md-4 mt-5 mb-5">
            <ul className="list-group">
              {MONTHS.map(this.createMonthElement)}
            </ul>
          </div>
        </div>
      </div>
    );
  }
}

export default App;
```

*Code snippet 1. App.js*

First, let's focus on its `render` method:

```jsx
render() {
  return (
    <div className="container">
      <div className="row">
        <div className="col-md-4 offset-md-4 mt-5 mb-5">
          <ul className="list-group">
            {MONTHS.map(this.createMonthElement)}
          </ul>
        </div>
      </div>
    </div>
  );
}
```

*Code snippet 2. App.js*

We see three `div` elements with class names that you might recognize if you're familiar with [Bootstrap](https://getbootstrap.com). Bootstrap helps us create layout for our page.

Inside of the `div` elements we have a `ul` element that has a JavaScript expression wrapped in `{` and `}`:

```jsx
{MONTHS.map(this.createMonthElement)}
```

*Code snippet 3. App.js*

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.

As you have guessed, the `this.createMonthElement` method returns another JSX expression that renders a month name. Let's take a look at it:

```jsx
createMonthElement = month => <Month month={month} key={month.number} />;
```

*Code snippet 4. App.js*

The `createMonthElement` method gets `month` as a parameter and returns an instance of `Month` component with `month` and `key` props.

The `month` is an object with month `name` and `number` for example:

```jsx
{
  name: "January",
  number: 1
}
```

*Code snippet 5. App.js*

It makes sense why we pass `month` object to `Month` component as a prop, but why do we need to pass the `key` prop? When we [create React elements dynamically](/how-to-create-components-dynamically-in-react-16/) we need to help React to uniquely identify those elements, so that React could figure out how to update the DOM efficiently.

## Creating the `Month` Item Component

Now let's take a look at the `Month` component:

```jsx
import React from "react";

const Month = props => <li className="list-group-item">{props.month.name}</li>;

export default Month;
```

*Code snippet 6. Month.js*

As you can see, the `Month` component renders `li` element with month name:

```jsx
<li className="list-group-item">{props.month.name}</li>
```

*Code snippet 7. Month.js*

Now you know how to loop through array of elements inside of JSX in React.

Thank you for reading this React tutorial!

Please take a look at [the complete source code on GitHub](https://github.com/fedosejev/how-to-loop-inside-jsx-in-react-16) and [the live version](https://fedosejev.github.io/how-to-loop-inside-jsx-in-react-16/) of our app.

I hope you've enjoyed this tutorial and I would love to hear your feedback in the comments. You can get in touch with me via [Twitter](https://twitter.com/artemy) and [email](mailto:artemij@fedosejev.com).

[Artemij Fedosejev](https://artemij.com)
