Skip to content
Advertisement

How do I chop/slice/trim off last character in string using Javascript?

I have a string, 12345.00, and I would like it to return 12345.0.

I have looked at trim, but it looks like it is only trimming whitespace and slice which I don’t see how this would work. Any suggestions?

Advertisement

Answer

You can use the substring function:

JavaScript

This is the accepted answer, but as per the conversations below, the slice syntax is much clearer:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement