JavaScript substr() with Example

The substr() method extracts the characters from a string, beginning at “start” and through the specified number of character, and returns the new sub string.


Start – Required. The index where to start the extraction. First character is at index 0.
Length- Optional. The number of characters to extract. If omitted, it extracts the rest of the string.

In the example
document.write(str.substr(1)+”<br />”);
First character of “Welcome to www.ispsd.Com” w is removed as seen in output.

First 3 characters of “Welcome to www.ispsd.Com” wel will be removed and after 9 characters rest of the words will be omitted too.




    elcome to www.ispsd.Com
    come to w

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.