If I have the following:
(8
Is there a way to get the number 8
out of it without splitting it? Using parseInt
returns NaN
. Is there an alternative to parseInt
that ignores non-numbers?
If I have the following:
(8
Is there a way to get the number 8
out of it without splitting it? Using parseInt
returns NaN
. Is there an alternative to parseInt
that ignores non-numbers?
- 1 possible duplicate of Javascript: strip out non-numeric characters from string – Brendan Long Commented May 29, 2013 at 0:28
2 Answers
Reset to default 7parseInt(str.replace(/[^\d]/g, ''), 10)
You can use a quick regex to match that number, and just prepend +
to cast to number:
var num =+ '(8'.match(/\d+/)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745264885a4619395.html
评论列表(0条)