Fine-Tuning Name Search


I'm trying to figure out how I can fine tune this program so that it only finds the defined name and not ones that might start with the same letter. Anyone actually gone through with this and have a solution?

var text = "Accent, Multiple, Ian, Civics, Classroom, Ian, Bathroom, Elephants, Ian, Homeroom";
var myName = "Ian";
var hits = [];
var nameCheck;

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

if(hits.length === 0){
    console.log("Your name wasn't found!");


This part of code...

i = j ?
Try removing it!


The i=j is how I have my code set up so that the first for loop knows where
to pick up. I'm trying to get it so that it only picks up my name. Say the
"text" variable has a string "Igloo" in it as well, the program would
currently push 'I' 'g' and 'l' into the hits array. I want my code to be
able to realize that it has picked up a string that isn't my name. Thanks


One thing...I see there is no use of... var nameCheck;


Oh yeah I know haha, for some reason I didn't implement the code as a


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