ScanSkill

substring

The substring() method is used to extract characters from two indices, or a single start point.

Syntax

string.substring(start, end)

string.substring(start)

Example

let text = "Hello world!";
let result = text.substring(0, 7);
console.log(result) // Prints: Hello w

result = text.substring(6);
console.log(result); // Prints: world!

The substring() method returns a string starting from the exact start index and till before the end index. It can be used with (start, end), or just (start).