String substring()
substring(start)
substring(start, end)
start
is a numberend
is a number
if start and end are less than 0, then they are considered zero.
substring() finds the substring of the given string from given start, to end position, and returns the substring.
Examples
1. substring(start)
let name = 'appleisgreat';
let output = name.substring(6);
console.log(output);
2. substring(start) with start as negative number
let name = 'appleisgreat';
let output = name.substring(-8); //negative start
console.log(output);
3. substring(start, end)
let name = 'appleisgreat';
let output = name.substring(4, 9);
console.log(output);