Extract starting at position 2, and extract the rest of the string:
var str = "Hello world!"; var res = str.substring(2);
Result:
llo world!
If “start” is greater than “end”, it will swap the two arguments:
var str = "Hello world!"; var res = str.substring(4, 1);
Result:
ell
If “start” is less than 0, it will start extraction from index position 0:
var str = "Hello world!"; var res = str.substring(-3);
Result:
Hello world!
Extract only the first character:
var str = "Hello world!"; var res = str.substring(0, 1);
Result:
H
Extract only the last character:
var str = "Hello world!"; var res = str.substring(11, 12);
Result:
!