JavaScript String substring() MethodThe JavaScript string substring() method fetch the string on the basis of provided index and returns the new sub string. It works similar to the slice() method with a difference that it doesn't accepts negative indexes. This method doesn't make any change in the original string. SyntaxThe substring() method is represented by the following syntax: Parameterstart - It represents the position of the string from where the fetching starts. end - It is optional. It represents the position up to which the string fetches. ReturnPart of the string. JavaScript String substring() Method ExampleLet's see some simple examples of substring() method. Example 1Let's see a simple example to print the part of the string. Test it NowOutput: Java Example 2In this example, we will fetch single character from the string. Test it NowOutput: t Example 3In this example, we will provide only the starting index. Test it NowOutput: point Example 4In this example, we will not pass any parameter with the method. In such case, the method returns the complete string. Test it NowOutput: Javatpoint Next TopicJavaScript String |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India