String.prototype.substring() - JavaScript - MDN Web Docs
Jul 10, 2025 ... The substring() method of String values returns the part of this string from the start index up to and excluding the end index, ...
Jul 10, 2025 ... The substring() method of String values returns the part of this string from the start index up to and excluding the end index, ...
The substring() method extracts characters from start to end (exclusive). The substring() method does not change the original string. If start is greater than ...
The JavaScript substring() function is one of the string methods used to pick a part (portion) of a string and return a new string. The substring function will accept two integer values.
Mar 22, 2020 ... JavaScript Substring Examples - Slice, Substr, and Substring Methods in JS ;.substring(startIndex, endIndex) ; const · = "I am learning JavaScript ...
JavaScript String substring() Method. Last Updated : 16 Jan, 2026.let s = "JavaScript is amazing!"; let res = s.substring(11); console.log(res); Immutability. Like most string methods in JavaScript, substring() does not alter the original string. Instead, it returns a new string.
The substring() function extracts a specific portion of a string. It returns a new string from the specified start index up to, but not including, the end index.
Oct 28, 2026 ... substring() , returns the part of a string between a start index and an optional end index. The original string is never modified: const text = ...
In this video, we'll use the substring method to parse out pieces of a JavaScript string by defining start and end indexes.
Examples of Using substring() in JavaScript · Extracting the First Character · Email Domain Extraction · Generating Preview Text · URL Path Extraction · Removing ...
In this article you are going to learn how to use the JavaScript substring() method to extract a substring from a string.The substring() method returns part of a string, meaning it returns a specified part of the string between start and end indexes.
Mar 28, 2011 ... In all cases, the second argument is optional. If it is not provided, the substring will consist of the start index all the way through the end ...
Apr 30, 2023 ... While the substring method is useful for extracting parts of a string, there are two other similar methods in JavaScript: slice and substr .
The substring() function does not alter the original string but returns the substring from the given string. You can also get a substring from a string using the string.substr(start, length) method, which takes the number of characters to extract as its second argument.
The substr() function is also common, but it is considered a "legacy function" in Mozilla's docs. You shouldn't use it when writing new code, but you may see it in existing JavaScript projects. The key difference between substring() and substr() is that substr() has a different 2nd parameter.
So to sum up the functional differences: substr(begin-offset, length) (deprecated) where begin-offset may also be negative. substring(begin-offset, end-offset-exclusive) where begin-offset is 0 or greater.