I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
Number.isNaN(myVar); // clearest and most idiomatic
myVar !== myVar; // NaN is the only value in JS that doesn't equal itself
Don’t use either of these:
myVar.isNaN; // will always evaluate to `undefined` unless myVar has a
// property called `isNaN`
isNaN(myVar); // evaluates to `true` for `NaN`, but also for any value that
// isn't a number (strings, objects, etc.)
When you splice the array, the array gets shorter but the value of i stays the same, so you end up skipping over one element each time you splice. To fix this, you can either decrement i within the conditional (this is risky and can lead to infinite loops if you’re not careful), or use the filter() method instead.
Note that your conditional doesn’t need to be that long. You’re testing for falsiness, which is an intrinsic feature in JavaScript. A quick way to check if a value is falsy is to use !val.