TypeScript String endsWith() Method Last Updated : 19 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The endsWith() method in TypeScript checks if a string ends with a specified substring. It accepts the substring to search for and an optional position parameter to end the search at a specific index, returning a boolean result.Syntaxstring.endsWith(searchString: string, position?: number): boolean;ParametersearchString: The string you want to see if the original string ends with.position (optional): Here you can pass an index position from where you want to start searching the default is the end of the string.Return Value: It returns true if the original string ends with searchString otherwise false. Example 1: Basic UsageThis example demonstrates how to use the endsWith() method to check if a string ends with a specific substring. JavaScript const str: string = "Hello, TypeScript!"; const result: boolean = str.endsWith("TypeScript!"); console.log(result); Output:trueExample 2: Validating a File ExtensionThis example shows how to use the endsWith() method to validate if a file name ends with a specific extension. JavaScript const fileName: string = "document.pdf"; const isValid: boolean = fileName.endsWith(".pdf"); console.log(isValid); // Output: true Output:true Comment More infoAdvertise with us Next Article TypeScript String endsWith() Method P pankajbind Follow Improve Article Tags : TypeScript Similar Reads TypeScript | String lastIndexOf() Method The lastIndexOf() is an inbuilt function in TypeScript which is used to get the index within the calling String object of the last occurrence of the specified value. Syntax: string.lastIndexOf(searchValue[, fromIndex]) Parameter: This method accepts two parameter as mentioned above and described bel 1 min read TypeScript String substr() Method The String.substr() method in TypeScript is an inbuilt function used to extract a portion of a string, starting at a specified index and extending for a given number of characters.Syntax: string.substr(start[, length])Parameter: This method accepts two parameters as mentioned above and described bel 3 min read Typescript String trimEnd method The trimEnd method, introduced in ECMAScript 2019 (ES10), is designed to remove whitespace characters from the end of a string. These whitespace characters include spaces, tabs, and line breaks. Its primary purpose is to sanitize and normalize strings, especially user inputs or data fetched from ext 2 min read Java String endsWith() with Examples In Java, the endsWith() method of the String class is used to check if a string ends with a specific suffix. The endsWith() method is present in the java.lang package. In this article, we will learn how to use the endsWith() method in Java and explore its practical examples.Example:In this example, 3 min read C# String EndsWith() Method In C#, the EndsWith() is a string method used to check whether the ending of the current string instance matches a specified string. If it matches, it returns true; otherwise, it returns false. Using the foreach loop, we can check multiple strings. This method supports overloading by passing differe 4 min read Like