How to remove last character in string (Javascript)

If you need to remove the last character from a string, you can use the substr function. This function takes a string as input and returns the portion of the string after the given character.

Patrick Wan
May 28, 2022

To use the substr function, you first need to specify the character you want to remove. Then, you need to provide the offset value. The offset value is the number of characters before the character you want to remove.

The following code example shows how to use the substr function to remove the last character from a string.

string name = “John”;return name.substr(0, name.length — 1); // "Joh"

This code example removes the last character from the string name and stores the result in the variable name.

--

--

Patrick Wan
Patrick Wan

Written by Patrick Wan

My name’s Patrick. I’m a Software Developer, experience in Laravel, Vue Js, React Js, Livewire, Jquery, Codegniter, NPM, GIT. I have 5 years plus experience.

No responses yet