Find the position of a substring:
let text = "hello world"
console.log(text.indexOf("o")) // 4 (first occurrence)
console.log(text.lastIndexOf("o")) // 7 (last occurrence)
console.log(text.indexOf("xyz")) // -1 (not found)
Both return -1 if the substring isn't found. Use this to check if a string contains something:
if (text.indexOf("world") !== -1) {
console.log("Found it!")
}