Your second "for" loop


#1

Hi, Can anyone help? I have no idea what's wrong with my code but it doesn't work:

var text = "Hello, my name is Sherlock and I'm the most \
wonderful dog in the world. If you ask yourselves why \ Sherlock, well it's because of Sherlock the famous detective.";
var myName = "Sherlock";
var hits = [];
for (var i = 0; i < text.length; i++){
if (text[i] === 'S') {
for (var j = i; j < (i + myName.length); j++){
hits.push(text[j]);
}
}

Thanks!


#2

@sherlockon,

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