Stop Using substr(): The Deprecated JavaScript API and the Right Replacements (slice vs substring)
Stop Using substr(): Why It Breaks, What To Use Instead Short answer: avoid substr(). It is deprecated in the standard and may be removed in the future. Prefer slice() in almost all cases (use substring() only when its specific behavior is required). Details and a migration checklist below. Why was substr() deprecated? String exposes three ways to cut text: slice(start, end) substring(start, end) substr(start, length) The first two follow the “start–end” convention. Only substr() takes a length, which makes the mental model inconsistent and increases bugs during quick editing and code reviews. Standards bodies and browser vendors discourage it and have marked it as deprecated. ...