EN
TypeScript - get substring from end
0 points
In this article, we would like to show you how to get a substring from the end in TypeScript.
Quick solution:
xxxxxxxxxx
1
text.substring(text.length - substringLength);
In this example, we specify the length of the substring we want to get, then we use substring()
method to get the last substringLength
characters of the text
string.
xxxxxxxxxx
1
const text: string = 'ABC DEF';
2
const substringLength: number = 3;
3
4
const result: string = text.substring(text.length - substringLength);
5
6
console.log(result); // DEF