tutorial |
---|
Using the knowledge you have from the previous example, now lets fix the .map
function again, but this time, starting from an array of objects.
const animals = [ { label: 'Horse' }, { label: 'Turtle' }, { label: 'Elephant' }, { label: 'Monkey' } ];
-
Update the code's .map function to create a new array of
<li>
's that each of them corresponds one animal from the original array and -
Include them all together inside the website.
const animalsInHTML = [
<li>Horse</li>,
<li>Turtle</li>,
<li>Elephant</li>,
<li>Monkey</li>
];
- You can use the second parameter of the map function as a
key
to uniquely identify each html item.