EN
JavaScript - get substring of string
0 points
In this article, we would like to show you how to get a substring of the string in JavaScript.
Quick solution:
xxxxxxxxxx
1
let text = 'ABCD';
2
let substring = text.substring(1, 3); // start from index 1 up to 3
3
4
console.log(substring); // BC
In this example, we present different cases of how to get a substring from the text
.
xxxxxxxxxx
1
let text = 'ABCDE';
2
3
let substring1 = text.substring(0, 3) // ABC
4
let substring2 = text.substring(3, 5) // DE
5
let substring3 = text.substring(3) // DE (from index 3 to the end of the string)
6
7
console.log(substring1) // ABC
8
console.log(substring2) // DE
9
console.log(substring3) // DE