String.prototype.substring() - JavaScript | MDN

developer.mozilla.org

Tin mới

HTML: Markup language

See all HTML references

Date & time formats

See all HTML guides

CSS: Styling language

See all CSS references

See all CSS guides

Centering an element

JavaScript: Scripting language

Standard built-in objects

Expressions & operators

Statements & declarations

See all JavaScript references

Control flow & error handing

Loops and iteration

Working with objects

See all JavaScript guides

Web APIs: Programming interfaces

Service worker API

Using the Web animation API

Using the Fetch API

Working with the History API

Using the Web speech API

All web technology

Progressive web apps

Learn web development

Getting started modules

Structuring content with HTML module

CSS styling basics module

Dynamic scripting with JavaScript module

Border-image generator

Border-radius generator

Box-shadow generator

Color format converter

Using substring() with length property

The following example uses the substring() method and length property to extract the last characters of a particular string. This method may be easier to remember, given that you don't need to know the starting and endin

The difference between substring() and substr()

There are subtle differences between the substring() and substr() methods, so you should be careful not to get them confused.

Differences between substring() and slice()

The substring() and slice() methods are almost identical, but there are a couple of subtle differences between the two, especially in the way negative arguments are dealt with.

String.prototype.replace()

The following example replaces a substring within a string. It will replace both individual characters and substrings. The function call at the end of the example creates a string Brave New Web from the original string B

Learn how to contribute

This page was last modified on Jul 10, 2025 by MDN contributors.

toLocaleLowerCase()

toLocaleUpperCase()

[Symbol.iterator]()

[Symbol.hasInstance]()

__defineGetter__()

__defineSetter__()

__lookupGetter__()

__lookupSetter__()

propertyIsEnumerable()

Community resources

Writing guidelines