Question: Write a function for checking string pelindrome

function isPalindrome(str) { // Function definition to check if a string is a palindrome // Remove non-alphanumeric characters and convert the string to lowercase const cleanStr = str.toLowerCase().replace(/[^a-z0-9]/g, ''); // Compare the characters in the cleaned string for (let i = 0; i < cleanStr.length / 2; i++) { // If characters from the beginning and end don't match, return false if (cleanStr[i] !== cleanStr[cleanStr.length - 1 - i]) { return false; } } // If the loop completes without returning false, the string is a palindrome return true; } // Example usage: const inputString = "kanaK"; document.write("Is the string a palindrome?", isPalindrome(inputString));

Output: