Use a for...in
loop to iterate over the animals
object that we’re importing on line 1. Before the animalFacts
definition, define an images
array. For each animal, add a new <img />
to that array.
Assuming animal
is the placeholder variable in your for...in
loop, each image should have the following attributes:
-
key
:{animal}
-
className
:'animal'
-
alt
:{animal}
-
src
:{animals[animal].image}
-
aria-label
:{animal}
-
role
:'button'
i don’t understand that why ‘src’ use square barcket for refer to animal [animal], I looking on anilmals.js animals is nested object. I confuse that square backet should use with array. Why in this case there use square backet whit object reference? I try to use src: {animals.animal.image} but It’s not work.