Please explain this code


#1

<for(var i=0;i<text.length;i++)
{
if(text[i]==="n")
{
for(var j=i;j<i+myName.length;j++){
hits.push(text[i+j]);
}

can anyoneplease explain how this 2nd for loop works..


#2

thanks to your if condition i will hold the index of the first letter of your name. So then you use the second for loop (j) to loop over i till i + myName.length, this way all letters of your name are found


#3

thank you :slight_smile:


#4

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