Languages
[Edit]
EN

JavaScript - indexOf() method from position

0 points
Created by:
Kenya-Spears
860

In this article, we would like to show you how to use indexOf() method starting from a specific position in JavaScript.

Practical example

Edit

The indexOf() method with specified second parameter - position, returns the index of the first occurrence of the specified string at a position greater than or equal to position (which is 0 by default).

Runnable example:

Output:

For comparison, if we had not specified the position parameter, the method would return the index of the first 'is' occurrence, which is 2.

Output:

References

Edit
  1. String.prototype.indexOf() - JavaScript | MDN

Alternative titles

  1. JavaScript - indexOf() method starting from given position
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join