var text = "Uncle Bob was in World War II. Many people believe World War II was
the most destructive war to date.";
var replace = text.indexOf("World War II");
for (var i = 0; i < text.length; i++) {
if (replace[i] !== -1) {
text = text.slice(0, replace) + "the second world war" +
text.slice(replace + 12);
}
break;
}
alert(text);
Without the break command, this is an infinite loop. I cannot figure out how to replace both World War IIs in text. I understand indexOf only deals with the first instance, however, how can I iterate through text to make it deal with both/all instances of what I want to replace? Besides using string replace method.