To find the first index of a substring in a string in TypeScript, you can use the indexOf() method on the string. This method returns the index of the first occurrence of the specified substring, or -1 if the substring is not found. Here's an example:
index.ts142 chars7 lines
In this example, we first define a string str and a substring substr. We then call the indexOf() method on str and pass in substr as the argument. The method returns the index of the first occurrence of substr in str, which is 6. Finally, we log the result to the console.
gistlibby LogSnag