How can javascript extract number from string?
Consider the following string in [removed]
var string="border-radius:90px 20px 30px 40px";
I want to extract the 4 numbers from that string and store them in an array called numbers.To do that I developed the following code:
var numbers=string.split("border-radius:");
numbers=numbers[1].split("px");
This code is working fine but I was wondering if there is a better approach/solution.
Your question - How can javascript extract number from string can be answered as -
I used the following regex to extract numbers from a string:var string = "border-radius:10px 20px 30px 40px";
var numbers = string.match(/d+/g).map(Number);