Node.js indexOf() function Last Updated : 30 Mar, 2023 Comments Improve Suggest changes Like Article Like Report The indexOf() function is a string function from Node.js which is used to find a string with another string. Syntax: str1.indexOf( str2 ) Parameter: This function uses two parameters as mentioned above and described below: str1: It holds the string content where another string is to be searched.str2: It holds the search string. Return Value: The function returns the index of the passed parameter. The below programs demonstrate the working of the indexOf() function: Example 1: javascript function findIndex(str) { let index = str.indexOf("awesome"); console.log(index); } const str = "gfg is awesome"; findIndex(str); Output: 7 Example 2: javascript function findIndex(str1, str2) { let index = str1.indexOf(str2); console.log(index); } const str1 = "Welcome to GeeksforGeeks"; const str2 = "to" findIndex(str1, str2); Output: 8 Comment More infoAdvertise with us Next Article Node.js indexOf() function T Twinkl Bajaj Follow Improve Article Tags : Web Technologies Node.js NodeJS-function Similar Reads Underscore.js _.indexOf() Function Underscore.js _.indexOf() gives the index of the element whose position we need to find. It starts to count the position of the elements in the array from 0. If the element is not present in the array then the result will be -1. Syntax:Â _.indexOf(array, value, [isSorted]);Parameters:array: It is the 3 min read Underscore.js _.indexBy Function The Underscore.js is a JavaScript library that provides a lot of useful functions that helps in the programming in a big way like the map, filter, invoke etc even without using any built-in objects. The _.indexBy() function is used to return a key for each element in the list and then returns an obj 3 min read Node.js MySQL INSTR() Function INSTR() function is a built-in function in MySQL that is used to get the position of the first occurrence of pattern in the text. Note: In NodeJs MySQL, INSTR() function is not case sensitive. Syntax: INSTR(text, pattern)Parameters: It takes two parameters as follows: text: It is the given text in w 2 min read Node.js slice() function The slice() function is a string function of Node.js which is used to extract sub-string from a string. Syntax: string.slice( start, end ) Parameters: This function uses three parameters as mentioned above and described below: string: It holds the string content. The substring is extracted from this 1 min read Underscore.js _.lastindexOf() Function _.lastIndexOf() function: It finds the index of an element in an array. If the element is repeated then it gives the index of that element which is closest to the end. It is used when we have a number of repeated elements in the array and we want to find the index of that repeated element which is n 3 min read Like