Extract a substring from text:
let result = text.substring(1, 4);
Start from position 2:
More examples below.
substring() method extracts characters, between two indices (positions), from a string,
and returns the substring.
substring() method extracts characters from start to end (exclusive).
substring() method does not change the original string.
If start is greater than end, arguments are swapped: (4, 1) = (1, 4).
Start or end values less than 0, are treated as 0.
First character is at index 0.
End position (up to, but not including).
If omitted: the rest of the string.
|A string||A string containing the extracted characters.|
If start is greater than end, parameters are swapped:
If "start" is less than 0, it will start from index 0:
Only the first:
Only the last:
substring() is an ECMAScript1 (ES1) feature.