EN
JavaScript - String indexOf() method example
0
points
// ONLINE-RUNNER:browser;
const text = 'ABCABC';
console.log(text.indexOf('A')); // 0
console.log(text.indexOf('B')); // 1
console.log(text.indexOf('C')); // 2
console.log(text.indexOf('A', 3)); // 3
console.log(text.indexOf('B', 3)); // 4
console.log(text.indexOf('C', 3)); // 5
console.log(text.indexOf('BC')); // 1
console.log(text.indexOf('BC', 3)); // 4
console.log(text.indexOf('123')); // -1
console.log(text.indexOf('123', 2)); // -1
1. Documentation
Syntax |
|
Parameters |
|
Result |
The method returns the index of the first occurrence of If the method is called with no arguments returns |
Description |
The method searches the entire calling string and returns the index of the first occurrence of the specified substring. If the second argument is given, the method returns the first occurrence of the specified substring at an index greater than or equal to the specified number. |