.push() from For Loop into empty array


I am trying to push the outcome of the second For Loop into the hits array, but I don't know what to enter into the parenthesis of the .push() command.

any help would be appreciated.

/*jshint multistr:true */
var text = "My dogs is named Phoenix, and my name is Allan.";
var myName = "Allan";
var hits = [];

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


Well the ".push()" function takes whatever is in the parenthesis and moves it to what's in front of the period.


hits.push(" ");
puts " " into the hits variable.

So if we're trying to put your name into the text variable we'd want to do something like this:


Side note:
The condition in your second for loop is a little wonkey woo.

(var j = i ; j < (i + myName.length) ; j++)

Remember, rule of thumb would be to only use elements of one for loop at a time. Otherwise there's not much of a point in having a second For-Loop in the first place.


Thanks for your help! I had tried to push (text[j]) without success, but that must have been because the second for loop was not correct.