尝试在其上运行Number()时检查空字符串或不是数字的元素
const latLong = ['1', 'g']
function findError(obj) {
// console.log(Number(obj))
return obj === '' || Number(obj) === NaN
}
console.log(latLong.find(findError))
它似乎捕获了空字符串,但没有捕获Number()部分,将不胜感激]]
[尝试在其上运行Number()时检查空字符串或非数字元素const latLong = ['1','g'] function findError(obj){// console.log(Number (obj))return ...
要检查Nan,您可以使用内置的isNaN()
功能。检查文档here。
let latLong = ['1', 'g'];
latLong = latLong.filter(el => {
return el === '' || isNaN(el);
});