//Searching for a substring
let str = "As sly as a fox, as strong as an ox";
let target = "as";
let pos = -1;
while ((pos = str.indexOf(target, pos + 1)) != -1) {
document.getElementById("result").innerHTML = pos;
document.getElementById("result").innerHTML += '<br />';
}
<h1>String</h1> <h2>Searching for a substring</h2> <blockquote> let str = "As sly as a fox, as strong as an ox"; let target = "as";<br /> result:<br /> <span id="result"></span> </blockquote>