Not sure why its not pushing letters to my array. please help


#1


var text = "blah blah blah blah blah blah blah blah Sean blah blah blah blah blah";
var myName = "Sean";
var hits = [];

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


#2

the problem seems to be in the first for loop:

for (var i = 0; i === text.length; i++)

the condition should while i is lesser then (<) text.length, so that in can increase until it looped over all text


#3

First for loop is the problem.Try this code.
for(var i=0; i<text.length; i++)


#4

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