myString.substring( start, [ end ] ) in ECMAScript 262

Return a specified subsection of the string.

Arguments

nametypedescription
start Number The index to start from.
end Number [optional] The index to stop before. If o
Return Type
String

Description

Like String.slice(), this method returns a subsection of the string starting and start and proceeding up to (but not including) end. Unlike slice(), if either argument is negative (or NaN), it is treated as 0, not as an offset from the end of the string. Further, if end occurs before start, the values are swapped and a valid subsection of the string is returned.

var msg = "Hello World";
var s1 = msg.substring(0,3);  // ** s1 is "Hel"
var s2 = msg.substring(6,10); // ** s2 is "Worl"
var s3 = msg.substring(10,6); // ** s3 is "Worl"
var s4 = msg.substring(3,-2); // ** s4 is "Hel"
var s5 = msg.substring(3);    // ** s5 is "lo World"