Sometimes, you need to write JavaScript expressions that change the structure of your markup. In the preceding section, you learned how to use JavaScript expression syntax to dynamically change the property values of JSX elements. What about when you need to add or remove elements based on JavaScript collections?
Throughout the book, when I refer to a JavaScript collection, I'm referring to both plain objects and arrays. Or, more generally, anything that's iterable.
The best way to dynamically control JSX elements is to map them from a collection. Let's look at an example of how this is done:
import React from 'react';
import { render } from 'react-dom';
const array = ['First', 'Second', 'Third'];
const object = {
first: 1,
second: 2,
third: 3
};
render(
<section>
<h1>Array</h1>
<ul>
{array.map(i => (
<li key={i}>{i}</li>
...