Skip to content
Related Articles

Related Articles

Node.js indexOf() function

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 13 Oct, 2021

The indexOf() function is a string function from Node.js which is used to find a string with another string.


str1.indexOf( str2 )

Parameter: This function uses two parameters as mentioned above and described below:

  • str1: It holds the string content where another string to be search.
  • str2: It holds the search string.

Return Value: The function returns the index of the passed parameter.

Below programs demonstrate the working of indexOf() function:

Program 1:

function findIndex(str) {
    var index = str.indexOf("awesome");
var str = "gfg is awesome";



Program 2:

function findIndex(str1, str2) {
    var index = str1.indexOf(str2);
var str1 = "Welcome to GeeksforGeeks";
var str2 = "to"
findIndex(str1, str2);



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!