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