JavaScript SubString

SubString()

The JavaScript SubString function is one of the JavaScript String function, which is used to extract the part of a string and return in new string. SubString() function will accept two arguments, first integer value is the index position where the extraction will start and the second integer value is the index position where the extraction will end. In this article we will show you, How to write SubString() Function in JavaScript Programming Language with example.

JavaScript SubString Syntax

The basic syntax of the SubString() function in JavaScript Programming Language is as shown below:

String_Object.substring(Start, End)

String_Object: Please specify the valid string from which you want to extract.

Start: Please specify the index position from where you want to extract.

End: Please specify the index position of the End point.

NOTE:

If you omit the second index then, SubString() function will start from the first index position and continue to the last

If you specify the second index value greater than first index value, SubString() function will swap two arguments.

If you are using the Negative numbers as a argument then, SubString() function will consider it as zero.

JavaScript SubString Function Example

The following set of examples will help you understand the SubString in JavaScript Programming Language.