Odd behaviour


#1


Hi all,

Please help me understand why this behaves wrong.
Why does it push 2 more characters then it should?

Thanks


/*jshint multistr:true */
/*jshint multistr:true */
var text = "se if to JAJA xxxspecify a block of code to be executed, if a specified condition is true se if to specify JAJA a block of code to be executed, if a specified asdasd JAJA condition is true";
var myName = "JAJA";
var hits = [];
for (var i = 0; i < text.length; i++) {
    if (text[i] === "J") {
        for(var j = i; j < (myName.length + i); j++) {
			hits.push(text[j]);
        }
    }
}

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


#2

J will find both j's in JAJA. if you would use Jaja it would work fine, since string comparison are case sensitive.


#3

Thanks.
It was so obvious, I had to miss it.


#4