Check for palindromes: odd exception to the program

hey so, my code works in a lot of cases, but it doesn’t return this (a man a canal etc) as true, even though it is a palindrome. any idea why?

var array = [];
function palindrome(str) {
  str.toLowerCase();
  var newStr = str.replace(/[^a-z0-9]+/gi, "");
  array = newStr.split('');
  array.reverse();
  var newString = array.join('');
  if (newString == newStr) {
    return true;
  }
  else {
    return false;
  }
  
}
palindrome("A man, a plan, a canal. Panama");

Change third line to str = str.toLowerCase(); I think.

Edit: Oh and line 6 array = array.reverse();

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

Try moving the array variable inside the function. Tests fail when you use global variables.

What values do you see when the dialog boxes pop up from:

alert(newString); alert(newStr);

Try the alerts before you test to see if the strings match or not, the info might help you figure it out.