Falsy Bouncer need help on this

I’ve been away for awhile reading up on scope and object prototypes and came back to try and finish this challenge. It seems to work perfectly for everything except null. I understand null is in a category by itself in JS and it has unique attributes. I’m sure one of these attributes is the reason why my code will not work. Can anyone give me a hint as to what I am doing incorrectly? Thank you in advance. Here is my code:

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  var newArray = [];
  var badListArray = [null, false, 0, "", undefined, NaN];
  for (i = 0; i < arr.length; i++) {
    if (badListArray.indexOf(arr[i]) === -1 ) {
      newArray.push(arr[i]);}
     
    }
   
    
  
  return newArray;
}
bouncer([1, null, NaN, 2, undefined]);

Your code so far

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  var newArray = [];
  var badListArray = [null, false, 0, "", undefined, NaN];
  for (i = 0; i < arr.length; i++) {
    if (badListArray.indexOf(arr[i]) === -1 ) {
      newArray.push(arr[i]);}
     
    }
   
    
  
  return newArray;
}
bouncer([1, null, NaN, 2, undefined]);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:54.0) Gecko/20100101 Firefox/54.0.1 Waterfox/54.0.1.

Link to the challenge:

NaN seems to check out fine. The code will only push values that are not found in arr into newArray. That is where i am a little confused. It seems that when the for loop iterates across null, the conditional that should stop it from being pushed is instead clearing it as something that is not found in the arr. I’ve added some additional code into the if conditional which is intended to single out null intentionally. Here is the modified line:

if (badListArray.indexOf(arr[i]) === -1 && badListArray.indexOf(arr[i]) !== null)

It is giving the same result. If this situation was being caused by NaN, it would make more sense. But null is supposed to be equal to itself and to undefined. What am I missing?

Oh wait the null that is getting passed into newArray is not the same null getting iterated over! Just realized something. Its coming from NaN isnt it?! OK one step closer to solving this! Lightbulb moment!

Thank you for all of your help. I figured out a solution (albeit not an efficient one). What I did was try to test for NaN the only way I know how, by making sure that the index value that was being iterated WAS equal to itself. If that failed, the value would not be pushed into newArray. I know there are much better ways to complete this task, but I’m just happy that it works. Here is the result I got that is functional:

  // Don't show a false ID to this bouncer.
  var newArray = [];
  var badListArray = [null, false, 0, "", undefined, NaN];
  for (i = 0; i < arr.length; i++) {
    if ((badListArray.indexOf(arr[i]) === -1) && (arr[i] === arr[i])) {
      newArray.push(arr[i]);}
     
    }
   
    
  
  return newArray;
}
bouncer([1,NaN,99,null,  "", false, 0]);```