String.prototype.slice(indexStart, indexEnd?) returns a new string with characters from indexStart up to (but not including) indexEnd. Negatives count from the end. Prefer slice() over deprecated substr().
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call string.slice. Start with this line.
JavaScript
str.slice(start, end?)
Call
What it does
str.slice(start, end?)
Primary signature.
string.slice(...)
Call with the arguments your case needs.
Built into JavaScript. Call slice(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
str.slice(start, end?)
Parameters
Parameter
Description
indexStart
Required. Where to begin (*omitted → treated as 0)
indexEnd
Optional. Stop before this index (default: end of string)
Return Value
Return Value
Description
*
The value returned by string.slice().
JavaScript Examples
Example 1 — Extract with Start and End
Pull a middle piece or everything from a start index onward.
Negatives in slice.slice(-4) starts four from the end → "ript".
Negatives in substring.substring(-4) treats -4 as 0 → whole string.
No swap in slice.slice(4, 1) returns "".
Swap in substring.substring(4, 1) becomes substring(1, 4) → "ava".
Compatibility
Browser & Runtime Support
String.prototype.slice() has been in JavaScript since the early language and is universal across browsers and runtimes.
✓ Baseline · Universal
String.prototype.slice()
Supported in all modern browsers, Internet Explorer, and every current Node.js release. Safe everywhere.
100%Browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
String.slice()Universal
Bottom line: Use confidently in any environment. Prefer slice() over substr() and reach for substring() only when you need its swap/negative-as-zero rules.
Frequently Asked Questions
String.prototype.slice(indexStart, indexEnd?) returns a new string with characters from indexStart up to (but not including) indexEnd. The original string is unchanged.
No. indexEnd is exclusive — the character at indexEnd is not included. For example "JavaScript".slice(0, 4) returns "Java" (indexes 0–3).
Negative values count from the end of the string. slice(-4) starts 4 characters from the end. You can mix positive and negative ends.
After negatives are normalized, if end is before or at start, slice() returns an empty string "". It does not swap the arguments.
slice() supports negative indexes. substring() treats negatives as 0 and swaps arguments when start > end. Prefer slice() in modern code.
No. Strings are immutable. slice() always returns a new string.