I am making a program in javascript which searches my name in a text and logs the frequency of the same in the console. I am first checking each letter of the text and when it matches with my name's first letter, I use another for loop which pushes letters into an array named hits.The letters from string "text" are pushed upto the length of my name using push(). After this I check whether the array "hits" and string "myName" are equal,and if they are equal I increase the count by one. But my code is not working and I don't know why,I have thought on it very much but all went in vain. Please help.
var text="abhishek apolo bpple abhishek",myName="abhishek",hits=[];
var count=0;
for(i=0;i<text.length;i++)
{
    if(text[i]===myName[0])
    {
        for(j=i;j<(i+myName.length);j++)
        {
            hits.push(text[j]);
        }
    }
    if(myName==hits)
    {
        hits=[];
        count=count+1;
    }
    hits=[];
}
if(count===0)
    console.log("Name not found!");
else
    console.log(count);
    
     
     
     
     
     
     
     
     
    