JavaScript Substring
substring() returns the part of a string between two indexes. Unlike slice(), it does not accept negative indexes — it treats them as 0 — and it swaps start/end if start is greater than end.
Syntax
str.substring(start, end) Examples
| Input | Arguments | Output |
|---|---|---|
| "hello" | 1, 3 | "el" |
Gotchas
- Negative arguments become 0 — use slice() when you need negative indexes.
Try it live
Type your input and see Substring transform it instantly.
Want to go further? Chain Substring with other functions in the visual Playground — pipe one output into the next and watch your data transform.