javascript - Remove string from array -
i have array contain number , string, want remove string array. here array:
var numbonly = [1, 3, "a", 7]; in case, want remove a numbonly (result numbonly = [1, 3, 7]).
thanks.
you can utilize this:
var numbonly = [1, 3, "a", 7]; var newarr = numbonly.filter(isfinite) // [1, 3, 7] the above works if don't have strings "1" in array. overcome that, can filter array this:
newarr = numbonly.filter(function(x){ homecoming typeof x == "number"; }); javascript arrays
No comments:
Post a Comment