On this page
  1. String.substr
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

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

Example

const s = "JavaScript";
// Legacy: s.substr(4, 6) === "Script"
console.assert(s.slice(4, 10) === "Script");

Linked from

Related notes