String.prototype.substring
Returns the part of the string from the start index up to and excluding the end index
Syntax
string.substring(indexStart, indexEnd?)Parameters
| Parameter | Type | Description |
|---|---|---|
| indexStart | number | Index of the first character to include |
| indexEnd | number | Index of the first character to exclude |
Return Value
A new string containing the specified part
Examples
const str = 'JavaScript';
console.log(str.substring(0, 4)); // 'Java'
console.log(str.substring(4)); // 'Script'const str = 'Hello World';
console.log(str.substring(6, 11)); // 'World'// substring swaps arguments if start > end
const str = 'abcde';
console.log(str.substring(3, 1)); // 'bc' (same as substring(1, 3))Understanding String.prototype.substring
The String.prototype.substring method in JavaScript returns the part of the string from the start index up to and excluding the end index. It belongs to the String object and is one of the most widely used methods for working with string values in modern JavaScript and TypeScript applications.
The method signature is string.substring(indexStart, indexEnd?). It accepts 2 parameters: indexStart, indexEnd. When called, it returns a new string containing the specified part. Understanding when and how to use substring() helps you write more expressive, readable code.
Common use cases for String.prototype.substring include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like string-slice, string-split, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for String.prototype.substring is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
More String Methods
Other methods in the String object
Related Tools
More String Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.