I'm trying to use the parseInt to show only numbers from the following array:
1,2,a,b
Here is my javascript code so far:
var filter_list = ["1,2,a,b"];
function myFunction() {
parseInt(filter_list);
return filter_list;
}
document.getElementById("display").innerHTML = filter_list;
Maybe my idea isn't even going to work. Would love some feedback.
You have array with one element that is string, so you could use join
and split
and then filter
method.
var data = ["1,2,a,b"];
var numbers = data.join(",").split(",").filter(Number);
console.log(numbers)