In this quick tip, you’ll see how to remove last character from string using JavaScript. You can remove last character using substring and slice.

Using slice

Here is the code to remove last character using slice method. slice method is used on an array.

let input = "codehandbook"

function removeLastCharacter(str){
  let charcter_arr = str.split('');
  return charcter_arr.slice(0, charcter_arr.length - 1).join('');
}

let output = removeLastCharacter(input);
console.log(`Output is ${output}`);

Using substring method

let input = "codehandbook"

function removeLastCharacter(str){
  return str.substring(0, str.length - 1);
}

let output = removeLastCharacter(input);
console.log(`Output is ${output}`);

Here are a couple of other articles related to this topic :