items: "Doughnuts, 4; doughnuts holes, 0.08; glue, 3.4"
function shoppingList(items) {
var split = items.split("");
var nums = split.filter(x => x != (/[a-z]+/gi));
console.log(nums);
}
I want to make this function filter out anything other than the numbers, including the ones with a decimal point. Is there a way to do this with a regex expression? I tried to make one, but either the regex is wrong, or something with my .filter() method. The end goal is to put all of the numbers in an array.
Console output:
[
'D', 'o', 'u', 'g', 'h', 'n', 'u', 't',
's', ',', ' ', '4', ';', ' ', 'd', 'o',
'u', 'g', 'h', 'n', 'u', 't', 's', ' ',
'h', 'o', 'l', 'e', 's', ',', ' ', '0',
'.', '0', '8', ';', ' ', 'g', 'l', 'u',
'e', ',', ' ', '3', '.', '4'
]