Search code examples
javascriptstringvariableserase

How to delete "px" from 245px


Whats a simple way to delete the last two characters of a string?


Solution

  • To convert 245px in 245 just run:

    parseInt('245px', 10);
    

    It retains only leading numbers and discards all the rest.