| Viewed 87 times

Check if the String is a Palindrome in javaScript?

A palindrome is a word, phrase, number or other sequences of characters that reads the same backward or forward, such as madam or kayak. I need a function that takes a string and determines whether it's a palindrome or not. The function should return a boolean (true or false value). *Should be case insensitive. *

1 Answer
Mohammad Qandeel

This function will help you to determines whether it's a palindrome or not

const isPalindrome = str => {
  const clean = str.toLowerCase().replace(/[\W\s-]/g, '');
  return clean.split('').reverse().join('') === clean;

Related Questions