Confused by this


I am confused by this and would love if someone could break it down for me, I will take the example provided:

const animals = [‘Grizzly Bear’, ‘Sloth’, ‘Sea Lion’];
for (let i = 0; i < animals.length; i++){

I do not understand what the following code does:
i < animals.length; i++)

Can someone explain what is happening here ?


Can you describe at least five concepts present in the above line?

Not sure if I understand where you are going with your reply. I am just not understanding how this makes it so that the loop continues until it reached Sea Lion.

i++ increases the value of i by one every time the function loops until it reaches a value of 2. It stops at 2 because animals.length is 3 and it is instructed to stop when i < animals.length.

I suspect @mtf is preparing a lengthier answer for you depending on how you answer his question!

1 Like

Ahhh okay well that really clears up my confusion, I did not want to move on until I understood this so thank you! And thank @mtf also. Much appreciated!


You’re very welcome :slight_smile:

const animals = ['Grizzly Bear', 'Sloth', 'Sea Lion'];


  • delimiters
    [] & '' => containers
    , => separator
    ; => end of statement
  • character strings
    'Grizzly Bear'
    'Sea Lion'
  • array
    [.., .., ..]
  • variable
  • declaration keyword
  • assignment

I’m not sure how this helps to answer @array0478424215 's question.

It’s not meant to. The question was meant to probe the OP’s level of understanding. Just giving an answer is not helping them to find their own solution.