Is there a built-in getter method that can parse an int from a string ("23px")?
I know I can use substring and then parseInt , but I want to know if there is another way for this.
substring
parseInt
parseInt will capture the first set of contiguous numbers:
parseInt('23px');
returns 23.
If there is a chance that there will be leading zeros, use radix:
parseInt('23px', 10);
which is a good habit in general.
parseInt can do this. Just use:
var num = parseInt("23px", 10);
He will analyze the whole part and ignore the rest.
Source: https://habr.com/ru/post/1380335/More articles:Is iOS5 ARC safe to schedule NSTimers from background selectors? - iosIs a DAO accessible only for accessing databases? - javaDisplaying data hierarchically using LINQ - c #Mongoid: inline documents are automatically initialized when the parent is built - initializationString Comparison JPA - stringR function call from C ++ on Windows - c ++WebSite standalone support - java-eeCreating projects in subfolders of [eclipse CDT] - eclipse"foreach" VS "List .Foreach" ... which wins - performance.Net - When is a List .ForEach preferable to a standard foreach loop? - performanceAll Articles