The JavaScript substring() String Method

By: Dusty Arlia
Published on Wednesday, April 3, 2013, 07:13 AM
Last Updated on Thursday, July 16, 2015 at 8:26 PM
Total Updates: 2

The JavaScript substring() string method extracts a range of characters from a string. The substring() method is passed two values: the first number is the idex where to start the extraction and the second number is the idex where to stop the extraction, not including itself. Keep in mind that the first character in the string is at index 0. If the second index number is missing, then the substring() method returns the rest of the string past the first index.

Here is an example:

var example_string = "My name is Dusty";
var first_name = example_string.substring(11,16);

In this example Dusty is written to the screen.