On this page
String.substr
Prev: matchAll | Up: String | Next: Math
Rel: String.prototype.slice(), String, String, RegExp & Intl Guide
Ref: MDN Web Docs — String.substr
Tags: #public #web #javascript #builtins #string #tier/legacy
Signature & Overview
str.substr(start, length)
Deprecated Annex B method taking (start, length) instead of (start, end).
Legacy / Avoid: Prefer String.prototype.slice() in all new code.
Notes & Pitfalls
- Deprecated legacy method: Its second parameter is length, not end index—always use
str.slice(start, end)in modern JavaScript.
Example
const s = "JavaScript";
// Legacy: s.substr(4, 6) === "Script"
console.assert(s.slice(4, 10) === "Script");
Linked from
Related notes
- tuts/javascript/builtins/String/matchAll Linked here; links to this page; shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String Linked here; links to this page; shared tags: #builtins, #javascript, #string, #web
- tuts/javascript/builtins/String/slice Linked here; shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/Math Linked here; shared tags: #builtins, #javascript, #web
- tuts/javascript/builtins/string_regexp_and_intl Linked here; shared tags: #builtins, #javascript, #web
- tuts/javascript/builtins/String/includes shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/replaceAll shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/split shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/trim shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/Array/at shared tags: #builtins, #javascript, #tier, #web