JavaScript substr Method

The JavaScript substr method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.
The JavaScript substr method does not change the original string.

Syntax:

string.substr(start,length)

Where,
start = Required. The position where to start the extraction. Starting index is 0
length = Optional. The number of characters to extract.

Example:

var str=”This is JavaScript substr() string method”;
var n=str.substr(8);
alert(n); // OUTPUT :JavaScript substr() string method

n=str.substr(8,19);
alert(n); // OUTPUT :JavaScript substr()

Live Demo of JavaScript substr method

Leave a Reply