Reputation: 110380
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?
Upvotes: 1
Views: 1595
Reputation: 94121
You can use a quick regex to match that number, and just prepend +
to cast to number:
var num =+ '(8'.match(/\d+/)
Upvotes: 3