String.slice() Slice a substring
Last updated: 2026-09-09
String.slice() Slice a substring
slice extracts a substring with negative index support; the original is untouched.
| Category | Strings |
|---|---|
| ES version | ES1 |
📝 Syntax
const sub = str.slice(start, end);
⚙️ Parameters
| start | Optional. Start (inclusive); negative counts from the end. |
|---|---|
| end | Optional. End (exclusive). |
Returns:The extracted substring.
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
Java
Script
💡 Tip slice supports negative indices, substring does not.
ℹ️ info slice(0, 3) takes first 3; slice(-3) takes last 3.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| String.slice() | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| Supported by all modern browsers | |||||
🏷️ Related Items
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
Qslice vs substring?
Aslice supports negative indices; substring does not. Prefer slice.
QIs end inclusive?
ANo — end is exclusive.
QHow to get the last character?
Astr.slice(-1).