jquery - Extract a number from a string? (Javascript) -


var amount = "(21)"; 

how go getting number? have gotten work with...

var amountresult = amount.substring(1, amount.length-1); 

...but feels incorrect.

what's better, more flexible way if not surrounded 2 characters?

thanks!

using regular expression more flexible:

var amountresult = amount.match(/\d+/)[0]; 

and turn number:

var amountresult = parseint(amount.match(/\d+/)[0], 10); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -