Skip to content

2 Methods to Remove Last Character from String in JavaScript

Category
JavaScript
Covers
string
Advertisement
On this page

Question: How do I remove the last character from a string in JavaScript or Node.js script?

This tutorial describes 2 methods to remove the last character from a string in JavaScript programming language. You can use any one of the following methods as per the requirements.

Method 1 – Using substring() function

Use the substring() function to remove the last character from a string in JavaScript. This function returns the part of the string between the start and end indexes, or to the end of the string.

Syntax:

Example:

Remove last character of string with substring function
Remove last character of string with substring function
Advertisement

Method 2 – Using slice() function

Use the slice() function to remove the last character from any string in JavaScript. This function extracts a part of any string and return as new string. When you can store in a variable.

Syntax:

Example:

Remove last character of string with javascript slice function
Remove last character of string with javascript slice function

Wrap Up

In this tutorial, you have learned about removing the last character of a sting in JavaScript. We used substring() and slice() functions to alter a string.

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top