Languages
[Edit]
EN

TypeScript - remove last character from string

0 points
Created by:
Mahir-Bright
1311

In TypeScript it is possible to remove last character from string in following ways.

1. Using String slice() method

const text: string = 'abc';
const substring: string = text.slice(0, -1);

console.log(substring); // ab

2. Using String substring() method

const text: string = 'abc';
const substring: string = text.substring(0, text.length - 1);

console.log(substring); // ab

3. Using String replace() method with regular expression

const text: string = 'abc';
const substring: string = text.replace(/.$/, '');

console.log(substring); // ab

4. Using String replace() method

const text: string = 'abc';
const substring: string = text.replace('c', '');

console.log(substring); // ab
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join