Remove null values from array using Array.indexOf?

Viewed 4707

I'm trying to find if there's a null value in my array without using for loops, mainly something similar to Array.indexOf. Undefined is NOT a string, it's a null value that comes up as undefined when I use console.log(ARRPREFIX)

var arr = ["**", undefined, null];
if (arr.indexOf(null) > -1) {
  console.log("Should be null");
  arr.splice(arr.indexOf(null), 1);
}

Above is my code, however it doesn't detect the undefined value, I also tried putting in "undefined" instead but that doesn't work.

2 Answers
Related