i just came across indexof() method and these two code left me scratching my head…
<h1> Code 1 </h1>
var str="where does this word occurs!";
var pos =str.indexOf("word");
document.getElementById("demo").innerHTML=pos;
<h1> code 2 </h1>
var str = "Please locate where locate occurs!";
var pos = str.indexOf("locate");
document.getElementById("demo").innerHTML = pos;
The first one gives me the position of 16 and the second one 7.For the first one,if i count from 0 to the “word” by coutning letters, it abruptly ends in the space before the "word"occurs.
for the second one,if i count by words it ends in pos 7.
i’m still gazing at this dazed and confused.haha.