**Apologies in advance if I’m not using the right tag, I’m not sure if this belongs in ‘learn-iterators’ or ‘learn-arrays’. But since the exercise I’m confused about is in the learn iterators section I’ll post it here.
So here the objective is to use the .map() to print the first letter of each element in the array and obtain a secret message:
const animals = ['Hen', 'elephant', 'llama', 'leopard', 'ostrich', 'Whale', 'octopus', 'rabbit', 'lion', 'dog'];
const secretMessage = animals.map(animal => animal[0]); //Prints 'HelloWorld'
What I don’t undersetand is why it works, since in the line where the secretMessage const is defined we type (animal => animal[0])
, right? but shouldn’t the animal[0]
print the first element in the array instead of the first letter of each one of the elements in the animal array?