Reputation: 1662
trying to check for an empty string or an element that is not a number when run a Number() over it
const latLong = ['1', 'g']
function findError(obj) {
// console.log(Number(obj))
return obj === '' || Number(obj) === NaN
}
console.log(latLong.find(findError))
It seems to be catching the empty string but not the Number() part, any help will be appreciated
Upvotes: 1
Views: 52
Reputation: 732
let latLong = ['1', 'g'];
latLong = latLong.filter(el => {
return el === '' || isNaN(el);
});
Upvotes: 0
Reputation: 1497
For checking Nan, you can use the inbuilt isNaN()
function. Check the documentation here
.
Upvotes: 1