[Beginner at Javascript] Edit: Sorry for not being clear, i was having problem understanding that we create "i" in the for loop. "text" does not have an "i", so how does text know to look for "i" as character. As far as i know, i can only access it like this, for example - text[0]
or text[2]
.
Below is the whole code, that i did on Codecademy. What does text[i]
mean.I mean how can we select i
from that. text
is not an array. I know we can select array positions but how does that work with strings?
/*jshint multistr:true */
var text = "My name is Jack, Jack";
var myName = "Jack";
var hits=[];
for (i=0;i<text.length;i++) {
if(text[i]==="J") {
for(j=i;j<myName.length +i;j++) {
hits.push(text[j]);
}
}
};
if(hits.length===0) {
console.log("name not found");
}
else {
console.log(hits);
}