The JavaScript substring method extracts the characters from a string, between two specified indices, and as a output there is a new sub string.
Syntax:
string.substring(from, to)
Where,
from = Required. The index where to start the extraction. Index starts from first character and its value starts from 0.
to = Optional. The index where to stop the extraction. If omitted, it extracts the rest of the string.
Example:
var str=”This is the JavaScript substring string method”;
document.write(str.substring(8)+”<br>”);
//OUTPUT: the JavaScript substring string method
document.write(str.substring(8,11));
//OUTPUT: the
Live Demo: JavaScript substring method