String.substring()

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

							string.substring(num1,
							num2)

string.substring(num)

Description

The substring() method of an instance of the String object returns the characters in the string starting with the indexed position num1 and ending with the character before num2. The string itself is zero based, so the first character is in position 0.

If you pass num1 as a negative number, it will be treated as 0. Likewise if you pass num2 as a value greater than the string.length property, it will be treated as string.length. And finally, if num1 equals num2, an empty string is returned.

As the syntax definition states, it is also possible to pass a single index location to the method. In this ...

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.