JavaScript Tutorial

Check if a String is Palindrome

Function to determine if a string reads the same forwards and backwards.

function isPalindrome(str) {
  const cleaned = str.toLowerCase().replace(/[^a-z0-9]/g, '');
  return cleaned === cleaned.split('').reverse().join('');
}