String.prototype.substring()

Returns the part of a string between two indices.

Since ES1 Spec ↗

Syntax

str.substring(start, end)

Parameters

NameTypeRequiredDescription
start number Yes Index of the first character to include.
end number No Index of the first character to exclude. Defaults to string length.

Returns

string — A new string containing the specified part.

Examples

console.log('hello'.substring(1, 4));
Output
ell
console.log('hello'.substring(4, 1));
Output
ell

Notes

Swaps the arguments if start is greater than end, and treats negative or NaN values as 0. For negative-index support use `slice` instead.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also