String.substr()

JavaScript1.0+, JScript1.0+ NES2+, Nav2+, IE3+, Opera3+ Syntax

							string.substr(num1,
							num2)

string.substr(num)

Description

The substr() method of an instance of the String object returns the characters in the string, starting with the indexed position num1 and counting to num2 characters. The string itself is zero based, so the first character is in position 0. It is also possible to pass num1 as a negative number. In this scenario, the string starts from the end of the string to begin the substring extraction.

As the syntax definition states, it is also possible to pass a single index location to the method. In this implementation, the method will not stop at a position and will return all characters until the end of the string. ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.