Is there any built in method to get which can parse int from string ("23px")?
I know I can use substring
and then parseInt
but I want to know if there is any other way available to do this.
parseInt
will grab the first set of contiguous numbers:
parseInt('23px');
returns 23.
If there is any chance there will be leading zeros, use a radix:
parseInt('23px', 10);
which is a good habit in general.
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