How to remove the last character from a string in javascript

Posted on November 1, 2021

Here the my preferred code:

const str = 'Hello!'
const res = str.slice(0, -1) // Hello

The -1 is the number of char you want to remove from the end. Neat!