
fromIndex: This is a location that specifies the starting point of the search within the calling text.search value: this is the value searched for.It returns the index of the initial occurrence of the defined value within the calling String object.

The indexOf() method in typescript starts the search at fromIndex and returns -1 if the supplied value cannot be found. Here we will see what is indexOf(), then we will see an example of how to use indexof() method to check if a string contains a substring in typescript. Use indexOf() to check if a string contains a substring in typescript These are examples of checking if a string contains substrings in typescript using the include() method. To compile the code run the below command and you can see the result in the console: ts-node containsSubstringĬheck if the string contains the substring in the typescript Open the code editor, create a file named ‘containsSubstring.ts’, and then write the below code: let str= 'hey! i am typescript. Let’s see how we can implement the include(), to check if the string contains a substring.Įxample 1: We will take a string and we will find a substring from that string, if it is available then it returns true or else false.

the item is the item to search in the array.Syntax of include() in typescript array.includes(item, index) The include() in typescript is used to check if a string contains a substring or not. Use include() to check if a string contains a substring in typescriptīefore we start checking if a string contains a substring in typescript, we need to see what is include() method.

Use search() to check if a string contains a substring in typescript.Use indexOf() to check if a string contains a substring in typescript.Use include() to check if a string contains a substring in typescript.
