String.substring(start, [end]) Last updated: 28. Aug 2024

The substring() method returns a part of the string between the start and end indexes, or to the end of the string.

Parameters

Name Type Description
start number The index of the first character to include in the returned substring.
end (optional) number The index of the first character to exclude from the returned substring. If omitted, extracts characters to the end of the string.

Returns

A new string containing the specified part of the given string.

Example

Code example (JS)

JS is normal JavaScript either running in the browser or on the Docly™ server.
let text = "Hello world";
let hello = text.substring(0, 5);
let world = text.substring(6);

write(hello); // Output: Hello
write("\r"); // new line
write(world); // Output: world

Output

The JS code above produces the output shown below:
Hello
world