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

String.slice

Prev: String | Up: String | Next: split
Rel: String, String, RegExp & Intl Guide
Ref: MDN Web Docs — String.slice
Tags: #public #web #javascript #builtins #string #tier/core


Signature & Overview

str.slice(startIndex, endIndex?)

Extracts a substring without mutating str; supports negative indices from the end.

Notes & Pitfalls

Example

console.assert("JavaScript".slice(0, 4) === "Java");
console.assert("JavaScript".slice(-6) === "Script");

Linked from

Related notes