Languages
[Edit]
PL

JavaScript - usuwanie ostatniego znaku ze zmiennej typu String

3 points
Created by:
Dirask JS Member
3430

W JavaScript usuni─Öcie ostatniego znaku z ci─ůgu mo┼╝liwe jest na kilka sposob├│w.

1. U┼╝ycie metody String slice()

// ONLINE-RUNNER:browser;

var text = "abc";
var substring = text.slice(0, -1); 

console.log(substring); // ab

2. U┼╝ycie metody String substring()

// ONLINE-RUNNER:browser;

var text = "abc";
var substring = text.substring(0, text.length - 1);

console.log(substring); // ab

3. U┼╝ycie metody String replace() z wyra┼╝eniem regularnym

// ONLINE-RUNNER:browser;

var text = 'abc';
var substring = text.replace(/.$/, '');

console.log(substring); // ab

4. U┼╝ycie metody String replace()

// ONLINE-RUNNER:browser;

var text = "abc";
var substring = text.replace("abc", "ab");

console.log(substring); // ab
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