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
Post a Comment