我正在尝试仅针对此阵列中的数字发出警报但不能!提前致谢
var clenk = [0, null, 42, undefined, "", true, false, NaN, "", "foo bar"];
var filteredArr = clenk.filter(function(val) {
return !(val === isNaN);
});
alert(filteredArr);
答案 0 :(得分:0)
你可以尝试
var clenk = [0, null, 42, undefined, "", true, false, NaN, "", "foo bar"];
var filteredArr = clenk.filter(function(val) {
return !isNaN(parseFloat(val));
});
alert(filteredArr);

答案 1 :(得分:0)
使用typeof
运算符检测val
的类型。
var clenk = [0, null, 42, undefined, "", true, false, NaN, "", "foo bar"];
var filteredArr = clenk.filter(function(val) {
return (typeof val === "number" && !isNaN(val));
});
alert(filteredArr);