javascript
Check if a string is Palindrome or not using Javascript
The below function written in Javascript can be helpful to check whether a string is Palindrome or not.
function palindrome_checker(str) {
const converted_str = str.split('').reverse().join('');
if (str === converted_str) {
console.log(str + " : String is Palindrome");
} else {
console.log(str + " : String is not Palindrome");
}
}
palindrome_checker('deified');
palindrome_checker('Ankit');
What is a Palindrome String
If you reverse a string from right to left or left to right and it remains same then the string will be called Palindrome string. Civic is a palindrome string means if you read it left to right or right to left it will have same characters in same orders.
Live Demo
Was this helpful?
Similar Posts
- Check whether a checkbox is checked or not using Javascript only
- Get all values from an array which does not exist in other array Lodash
- Check if Array includes String(Case Insensitive) Javascript
- Check if string includes a substring Javascript (Multiple Methods)
- Methods to check empty array using javascript
- Check if dark mode is enabled using Javascript
- Check if a number is odd or even using Javascript