javascript
Remove last character of a string in Javascript
var str = "Hello World";
var finalStr = str.substring(0, str.length-1);
Output
Hello Worl
To remove the last character from a string in javascript you can use .substring() function of javascript and pass start and end index as a parameter. Here we have passed the start index as 0 and the end index as string length - 1.
Was this helpful?
Similar Posts
- Efficiently Remove the Last Element from an Array in JavaScript [6 Methods Explained]
- Remove last n elements from an array using Lodash
- Remove items starting from last untill given condition is false Lodash
- Lodash - Get all elements of array except the last one
- Lodash - Get the last element of an array
- Remove new line separator from start and end positions of string in Javascript
- Remove all whitespaces from a string using javascript