Why i could not egual to =?

var animals = [“Grizzly Bear”, “Sloth”, “Sea Lion”];

for (var i = 0; i < animals.length; i++) {

hi every one
i have a questions, when for works .
why i<animals.length?
it means the last item would not check .is not it ?
because for example ,it begins at 0,then 1,2,
as i<2,it will stop at 1.this means it will not check the last item .
so i did not understand why .
the correct way is for i is equal to i=animals.length.
therefore it can arrive the last item.
instead of i<animals.length.

could anyone give me explain?

i am confused, how did you get to objects, getters and setters and so on, without understanding this fundamental concept?

well, .length starts counting at 1 so length is 3, which we can verify:

var animals = ["Grizzly Bear", "Sloth", "Sea Lion"];

while indexes start counting at zero ( so the indexes are: 0, 1, an 2. So the loop is fine like you have it


haha ,thank you for your reply.
je vous remercie votre gentillness mille fois.

i do these exercises at the second time
when i did them at the first time ,i had many difficulty ,but now ,i can do many exercises very rapidly.
of course ,maybe they are foundamental exercises .
but i thank you for your help.

best wish for the good man.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.