You're confusing substring() and substr(): substring() expects two indices and not offset and length. In your case, the indices are 5 and 2, ie characters 2..4 will be returned as the higher index is excluded.

Answer from Christoph on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substring
String.prototype.substring() - JavaScript | MDN
The substring() method of String values returns the part of this string from the start index up to and excluding the end index, or to the end of the string if no end index is supplied.
🌐
W3Schools
w3schools.com › jsref › jsref_substring.asp
JavaScript String substring() Method
The substring() method extracts characters, between two indices (positions), from a string, and returns the substring.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substr
String.prototype.substr() - JavaScript | MDN
The substr() method of String values returns a portion of this string, starting at the specified index and extending for a given number of characters afterwards.
🌐
Mimo
mimo.org › glossary › javascript › substring
JavaScript Substring Method: Learn String Extraction
The substring() method in JavaScript extracts a portion of a string and returns it as a new string without modifying the original string.
🌐
Refine
refine.dev › home › blog › tutorials › javascript substring method
JavaScript Substring Method | Refine
January 1, 2025 - JavaScript substring() is a String method that is typically used to extract and store part of a string.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-substring-examples-slice-substr-and-substring-methods-in-js
JavaScript Substring Examples - Slice, Substr, and Substring Methods in JS
March 22, 2020 - You can also watch the video version of the example usages here: Let’s start with the substring( ) method. This method basically gets a part of the original string and returns it as a new string.
Find elsewhere
🌐
Bennadel
bennadel.com › blog › 2159-using-slice-substring-and-substr-in-javascript.htm
Using Slice(), Substring(), And Substr() In Javascript
April 21, 2020 - If it is not provided, the substring will consist of the start index all the way through the end of the string. For both the slice() and substring() methods, the second argument is exclusive; that is, the resultant substring will not contain the character at the final index. Let's take a look as these three approaches in action: <!DOCTYPE html> <html> <head> <title>Extracting Substrings In Javascript</title> <script type="text/javascript"> // For these demos, let's create a numbered string so that // we can easily see where the indexes come into play with // all of the substring methods.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-string-substring-method
JavaScript String substring() Method - GeeksforGeeks
If only the starting index is provided, substring() will return the substring from that index to the end of the string. ... Like most string methods in JavaScript, substring() does not alter the original string.
Published   January 16, 2026
🌐
TechOnTheNet
techonthenet.com › js › string_substring.php
JavaScript: String substring() method
In JavaScript, substring() is a string method that is used to extract a substring from a string, given start and end positions within the string.
🌐
Medium
medium.com › programming-essentials › how-to-extract-a-substring-in-javascript-e0d521cb030f
How to Extract a Substring in JavaScript | by Cristian Salcescu | Frontend Essentials | Medium
May 10, 2021 - const quote = "Winter is coming";const part1 = quote.substr(0, 6); //Winterconst part2 = quote.substr(10, 6); //coming · Notice that the first character is at index 0. The start index is required but the length is optional. If omitted it extracts the rest of the string.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › difference-between-substr-and-substring-in-javascript
Difference between substr() and substring() in JavaScript - GeeksforGeeks
July 11, 2025 - const str1 = "GeeksForGeeks"; const ...tr.substring(7) =", substringResult); ... This function gets the characters from a string, between two specified indices, and returns the new string....
🌐
Stack Abuse
stackabuse.com › bytes › difference-between-substr-and-substring-in-javascript
Difference Between substr() and substring() in JavaScript
September 13, 2023 - The substr() method in JavaScript is used to extract parts of a string, starting from the index specified and extending for a given number of characters afterwards.
🌐
Droidscript
droidscript.org › javascript › Global_Objects › String › substring().html
str.substring()
JavaScript Reference · Contents · Basics · Statements · Operators · Global Objects · The substring() method returns a subset of a string between one index and another, or through the end of the string. str.substring(indexStart[, indexEnd]) indexStart ·
🌐
W3Schools
w3schools.com › jsref › jsref_indexof.asp
JavaScript String indexOf() Method
break class const continue debugger do...while for for...in for...of function if...else let return switch throw try...catch var while JS Strings · at() charAt() charCodeAt() codePointAt() concat() constructor endsWith() fromCharCode() includes() indexOf() isWellFormed() lastIndexOf() length localeCompare() match() matchAll() padEnd() padStart() prototype repeat() replace() replaceAll() search() slice() split() startsWith() substr() substring() toLocaleLowerCase() toLocaleUpperCase() toLowerCase() toString() toUpperCase() toWellFormed() trim() trimEnd() trimStart() valueOf() JS Typed Arrays
🌐
W3Schools
w3schools.com › jsref › jsref_includes.asp
JavaScript String includes() Method
break class const continue debugger do...while for for...in for...of function if...else let return switch throw try...catch var while JS Strings · at() charAt() charCodeAt() codePointAt() concat() constructor endsWith() fromCharCode() includes() indexOf() isWellFormed() lastIndexOf() length localeCompare() match() matchAll() padEnd() padStart() prototype repeat() replace() replaceAll() search() slice() split() startsWith() substr() substring() toLocaleLowerCase() toLocaleUpperCase() toLowerCase() toString() toUpperCase() toWellFormed() trim() trimEnd() trimStart() valueOf() JS Typed Arrays
🌐
Oodlestechnologies
oodlestechnologies.com › blogs › how-to-work-substring-method-in-javascript
How to work Substring method in JavaScript
February 14, 2020 - Now, the index position within string starts with 0 that means at index position 0 we have this letter 'J' and at index position 2 we have this letter 'a' and so on. If the value of the start parameter is greater than the value of the end parameter, this method will swap the two arguments. This means start will be used as end and end will be used as a start. var str = "JavaScript Blog" var result = str.substring(10, 0); console.log(result) // JavaScript
🌐
Ariya
ariya.io › 2014 › 02 › javascript-string-substring-substr-slice
JavaScript String: substring, substr, slice · ariya.io
February 27, 2014 - Even worse, sometimes it is easy to fall into the trap and choose the wrong function. String’s substring (ECMAScript 5.1 Specification Section 15.5.4.15) is the first logical choice to retrieve a part of the string.