Function Updated 17 Oct 2026
String.slice(start, [end])
Returns the part of the string from start up to (not including) end. Negative values count from the end of the string. Unlike substring(), slice() does not swap start and end. The original string is not changed.
Parameters
startnumberrequiredIndex of the first character to include. A negative value counts from the end.
endnumberoptionalIndex of the first character to exclude. A negative value counts from the end. Default: the end of the string.
Returns
The extracted text. An empty string if start is after end.
Example
Normal JavaScript, running in the browser or on the Docly™ server.
const text = "Hello world";
write(text.slice(0, 5)); // Hello
write("\n");
write(text.slice(-5)); // world
write("\n");
write(text.slice(6, -2)); // worThe JavaScript above produces this output:
Hello
world
wor