String.indexOf

indexOf — Finds the position of the first occurrence of a string within a string.

Description

String.indexOf(string string, [integer offset])

Parameters

Name Description Type Default Optional
string string No
offset integer Yes

Return values

number primitive.

Examples

Example #1 – indexOf example
var txt = 'Hello World'; console.log(txt.indexOf('o')); // Will return 4. console.log(txt.indexOf('o', 5)); // Will return 7. console.log(txt.indexOf('a')); // Will return -1.

External references