Why doesn't it push the first letter in your name twice


#1

for (var i = 0; i < text.length; i++) {
if (text[i] === "J") {
console.log (i)
for (var h = i; h < (i + myName.length); h++) {
console.log (h)
hits.push(text[h]);

I dont understand why it doesn't push it twice. my name is Jeremy and when i console log var H it says 0012345 as it is outputting i + myName.length. so shouldnt it push JJeremy? Can someone better explain this loop to me? Thanks!


#2

Please post your full code, what's the text variable?


#3

why are you pushing?


#4

/*jshint multistr:true */
var text = "Jeremy is going to travel the world. Jeremy is going to see a lot of interesting things!"
var myName = "Jeremy"
var hits = []

for (var i = 0; i < text.length; i++) {
if (text[i] === "J") {
console.log (i)
for (var h = i; h < (i + myName.length); h++) {
console.log (h)
hits.push(text[h]);

    }
}

};

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


#5

try

text[i]

and

text[h]

for console.log