Palindrome Checker Can't Do Spaces

I’m having trouble with the palindrome checker challenge. My function works fine for the first few test cases, but fails as soon as it encounters spaces, like “race car.” According to the challenge rules, the checker should ignore non-alphanumeric characters and convert everything to lowercase, which I’ve done, but for some reason the section of the code that removes non-alphanumeric characters doesn’t seem to work on spaces, despite the fact that spaces don’t meet /^[a-z0-9]/ and I’ve said to remove things that don’t meet those requirements. Any input with spaces in it is automatically labelled not a palindrome. What’s wrong here?

function palindrome(str) {
  // Make an array
  arr = str.split('');

  // Make array all alphanumeric and lowercase
  for (var i = 0; i < arr.length; i++) {
    if (arr[i] != /^[a-z0-9]/) {
      arr.splice(i, 1);
    }
  }
  str = arr.join("");
  str = str.toLowerCase();

  // Test if palindrome
  for (var j = 0; j < Math.floor((str.length + 1) / 2); j++) {
    if (str[j] != str[str.length - 1 - j]) {
      return false;
    }
  }

  return true;
}

That helped a lot. Thank you. One more problem, it doesn’t always work with one try. It will leave some special characters and the only way I’ve founded to fix it is to filter it out again.

Nevermind. I found a better way using filter and the regex you helped me with, now to whole thing looks like this:

function palindrome(str) {
  // Make an array
  str = str.toLowerCase();
  arr = str.split('');

  // Make array all alphanumeric and lowercase
  arr = arr.filter(function(char) {
    return !/[^a-z0-9]/.test(char);
  });

  str = arr.join('');

  // Test if palindrome
  for (var j = 0; j < Math.floor((str.length + 1) / 2); j++) {
    if (str[j] != str[str.length - 1 - j]) {
      return false;
    }
  }

  return true;
}

Thank you so much for your help. Much appreciated.