Favorites

JavaScript String.prototype.substring() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
String.prototype.substring()
JavaScript String Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The substring() method returns the part of a string between two indexes. Unlike slice(), it doesn't accept negative indexes.

Description

The substring() method returns the part of the string between the start and end indexes. It differs from slice() in two ways: negative values are treated as 0, and if start is greater than end, the two are swapped. Because those rules can hide mistakes, slice() is usually the better choice.

If either argument is NaN, it's treated as 0, and values larger than the string's length are treated as the length. With only one argument, it returns everything from that index to the end, like slice() with one argument.

The swapping behavior can be useful when you have two positions and don't know which comes first, but in most code it hides mistakes. There's also an older, deprecated substr() method, which takes a start and a length; avoid it in new code and use slice() instead.

Syntax

string.substring(start)
string.substring(start, end)

Parameters

  • startThe index to start at.
  • endOptional. The index to stop before.

Return Value

A new string containing the extracted part.

Example

const s = 'Mozilla';
console.log(s.substring(1, 3));
console.log(s.substring(3, 1));     // swapped
console.log(s.substring(-3));       // treated as 0
console.log(s.slice(-3));

Browser Support

The following information will show you the current browser support for the String.prototype.substring() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee