An array
where you are starting from index to 0
and going upto array's length
one by one. Let us suppose
var arr = ['a', 'b', 'c', 'd', 'e']
Now this array
contains 5 elements
. Well, if you start counting it from 0
, your fifth element index
is 4
. But in your loop
you are breaking it when the index is 5. As there is no element on index 5
you are getting error undefined.
solution
Where you check if index is <=
replace that with <
as when the loop index reaches equals to the total number element in your array which is 5 it get break and exit.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…