The indexOf() function returns the first occurrence of a given value in a string. If the supplied value cannot be found, it returns -1.
string.indexOf(searchvalue, start)
let str = 'Welcome to Techstackguru tutorials';
let index = str.indexOf('Techstackguru');
console.log(index); // 11
You may use the indexOf method of an array if the item is a primitive value, such as a string or number.
const alphabets = ['a', 'b', 'c']
const index = alphabets.indexOf('c')
console.log(index); // 2
let str = 'hello world';
let index = str.indexOf("World");
console.log(index); // -1
If the supplied value not found, indexOf function returns -1 value.