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 โบ substring
String.prototype.substring() - JavaScript - MDN Web Docs
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.
string - javascript substring - Stack Overflow
the most darndest thing! the following code prints out 'llo' instead of the expected 'wo'. i get such surprising results for a few other numbers. what am i missing here? alert('helloworld'.substri... More on stackoverflow.com
What is the most efficient way to find substrings in strings?
Easiest solution is to just use the 'in' operator like this: if "Leonardo DiCaprio" in article_title: return True And according to the top answer here it's also the fastest: whats-a-faster-operation-re-match-search-or-str-find Edit:cant get that return statement to indent for the life of me, you get the idea More on reddit.com
How to remove last word from string in JavaScript
Maybe not the most preferred method but splice the string using spaces, remove the last index on the returned array, then rejoin the array indexes back together . . . Or probably better way is to just use lastIndexOf string method for a space, and then create a substring from the beginning to that index . . . someString = someString.substring(0, someString.lastIndexOf(" ")) More on reddit.com
Why do we have a String.slice() method in JS ?
https://stackoverflow.com/a/2243835 This answer outlines the commonalities and differences between the two. More on reddit.com
JavaScript Substring Method in 5 Minutes
06:32
Master Substring Searches in JavaScript! Quick & Easy Tutorialโ ...
02:27
JavaScript Basics - substr() - YouTube
07:04
JavaScript Substring Method in 5 Minutes - YouTube
00:53
substring in Javascript ( Interview Question ) - YouTube
GeeksforGeeks
geeksforgeeks.org โบ javascript โบ javascript-string-substring-method
JavaScript String substring() Method - GeeksforGeeks
The substring() method is used to extract a portion of a string. It returns a new string without changing the original one. Extracts characters between two given indices.
Published: January 16, 2026
JavaScript Tutorial
javascripttutorial.net โบ home โบ javascript string methods โบ string.prototype.substring()
JavaScript Substring(): Extract a Substring from a String
November 3, 2024 - Then the substring returns the domain that starts from the index of @ plus 1 to the end of the string. The JavaScript substring() method returns the substring from the start index up to and excluding the end index.
Tabnine
tabnine.com โบ home โบ how to use the substring method in js
How to Use the substring Method in JS - Tabnine
July 25, 2024 - In the example above, the substring() method is used to extract the portions of the string str between index 11 (which is included in the result) and index 18 (which is not included). The substring() method returns a new string as its result. Note: JavaScript strings are immutable, meaning that a new string is created in memory for the return value of substring().
Codecademy
codecademy.com โบ docs โบ javascript โบ substring
JavaScript | Substring | Codecademy
May 29, 2025 - The .substring() method in JavaScript extracts a portion of a string from one position to another (exclusive) and returns a new string.
ReqBin
reqbin.com โบ code โบ javascript โบ i5foejaa โบ javascript-substring-example
How do I get a substring from a string in JavaScript?
August 26, 2026 - To get a substring from a string in JavaScript, you can use the built-in string.substring(start, end) method.
Top answer 1 of 6
105
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.
2 of 6
67
You have three options in Javascript:
//slice
//syntax: string.slice(start [, stop])
"Good news, everyone!".slice(5,9); // extracts 'news'
//substring
//syntax: string.substring(start [, stop])
"Good news, everyone!".substring(5,9); // extracts 'news'
//substr
//syntax: string.substr(start [, length])
"Good news, everyone!".substr(5,4); // extracts 'news'
TechOnTheNet
techonthenet.com โบ js โบ string_substring.php
JavaScript: String substring() method
This JavaScript tutorial explains how to use the string method called substring() with syntax and examples. 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.