EN
TypeScript - remove last character from string
0 points
In TypeScript it is possible to remove last character from string in following ways.
xxxxxxxxxx
1
const text: string = 'abc';
2
const substring: string = text.slice(0, -1);
3
4
console.log(substring); // ab
xxxxxxxxxx
1
const text: string = 'abc';
2
const substring: string = text.substring(0, text.length - 1);
3
4
console.log(substring); // ab
xxxxxxxxxx
1
const text: string = 'abc';
2
const substring: string = text.replace(/.$/, '');
3
4
console.log(substring); // ab
xxxxxxxxxx
1
const text: string = 'abc';
2
const substring: string = text.replace('c', '');
3
4
console.log(substring); // ab