How to remove the last character from a string in javascript

• 1 min read

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!