Loop won't push values to hits array


#1

/*jshint multistr:true */
var text = "Mother birds feeding their young says Mandy. \ There's beauty in what we believe he said, open your eyes Mandy.";
var myName ="Mandy";
var hits = [];

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

I don't fully understand how to use .push() and I believe that what I am inputting in the array is the problem. Will someone please explain?


#2

Your first FOR-loop definition is a mess...
Have a read
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for

In the first for-loop you are running over the text
‚ó¶character by character using text[i] as character-value, as long as text.length
‚ó¶comparing it to "M" in a IF-statement

Then further on you are using the push() Method
google search
google search
javascript push array site:developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push
(also look in left-hand collumn Methods.... )

javascript push array site:stackoverflow.com