Learning JavaScript: Iterators


How do you know to use .charAt(0)?
‘’‘let secretMessage = animals.map(animal => animal.charAt(0));’’’


Quite possibly you don’t. But at this point we do know how to use str[0] to represent the first index position of a string. If the String.charAt() method is new to you, then consider your education augmented that slight bit. Add it to your library. Why look a gift horse in the mouth?


Is there a library we can access? (for this information). And I don’t remember using str[0] (my memory could be off). Thanks for your help.


You’d look at what you’re trying to do - get a specific character from a string, and then you’d look up what behaviour is supported by string (and looking up a character by position sounds like something that would exist)

google “mdn string” ->


At the start of the track there is a link in one of the earlier lessons that points to Mozilla Developer Network. Go back and find that link, or bookmark the one above and keep it nearby at all times. Don’t just race through a lesson. You’ll never remember anything that way. Stop and do the reading and research that would accompany the new concepts in the lesson.


has been explained in early lessons on strings and also in lessons on arrays.

myString = "The start of a new day"
// 22
// undefined
console.log(myString[myString.length - 1])
// y
// T

We’re at a point in the course where it is anticipated all the elementary concepts are behind us now and we are ready to push ahead into advanced concepts. If you have scrambled through the units without stopping to review, then you will find yourself right back where you started… The beginning.

Now would be a good time to dig deep into the subject of String objects (and Array objects) and suss out all of the available methods inherited from their constructor prototype.

Take for instance String.slice()

// y
console.log(myString.slice(0, 1))
// T

And the ever popular, String.indexOf()

// 0
// 21
// 19

Whatever you do, don’t put the course in your rearview mirror until you can walk through every exercise in your sleep. That is the burden we take upon ourselves as self-motivated learners. There is nobody looking over our shoulder to correct our errant ways. All the more reason to do extensive reading on every topic, else one day you may find yourself caught with your trousers down.