Function Updated 28 Aug 2024
String.substring(start, [end])
The substring() method returns a part of the string between the start and end indexes, or to the end of the string.
Parameters
startnumberrequiredThe index of the first character to include in the returned substring.
endnumberoptionalThe 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
Normal JavaScript, 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: worldThe JavaScript above produces this output:
Hello
world