html - How to fetch Digits from a String in javascript? -
i have following string in javascript:
var xyz= "m429,100l504.5,100l504.5,106l580,106l570,98m580,106l570,114";
i want fetch numbers , store in array.
i tried following code:
var x=xyz.match(/\d+/g);
and got following output:
0: "429" 1: "100" 2: "504" 3: "5" 4: "100" 5: "504" 6: "5" 7: "106" 8: "580" 9: "106" 10: "570" 11: "98" 12: "580" 13: "106" 14: "570" 15: "114"
as can see floating point values such 504.5 has come seperately.
how can fetch properly?
you can change regex 1 :
var x=xyz.match(/[0-9.]+/g);
it allow capture number , float well.
Comments
Post a Comment