How can I remove the following suffix:
from some string if it contains that suffix ?
Like enter I get string which can be measure of width of div and that can ends with 'px', '%', 'em' and can also be without, so I need to remove suffix if it exists.
var s = "34em";
parseInt(s, 10); // returns 34
this works for em, px, %, pt
... and any other suffix even if it has a space before.
Use parseFloat()
instead if you have non-integer values
var s = "81.56%";
parseFloat(s); // returns 81.56
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With