indexof string code example

Example 1: js indexof string

const paragraph = 'The quick brown fox';

console.log(paragraph.indexOf('T'));
>> 0

console.log(paragraph.indexOf('h'));
>> 1

console.log(paragraph.indexOf('Th'));
>> 0

console.log(paragraph.indexOf('he'));
>> 1

console.log(paragraph.indexOf('x'));
>> 18

Example 2: js indexof string

str.indexOf(searchValue[, fromIndex])

Example 3: indefOf

const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];

console.log(beasts.indexOf('bison'));
// expected output: 1

Example 4: indexof javascript

arr.indexOf(searchElement[, fromIndex])