Uses the split(), reverse(), and join() Methods

Another approach, which is through the shortest approach, uses the split(), reverse(), and join() methods.

  • Split the string of characters into several different characters (which is though unsorted at the moment).
  • Use the reverse() method to reverse all the characters of the string alphabetically.
  • Then apply the join() method in order to join all the characters of the string (which are now sorted).

Example: Below is the implementation of the above approach:

Javascript
// JavaScript code in order to check string palindrome...

let checkPalindrome = (stringg) => {
    return stringg === stringg.split("").reverse().join("");
};

console.log("Is Palindrome? : " + checkPalindrome("noon"));
console.log("Is Palindrome?: " + checkPalindrome("apple"));

Output
Is Palindrome? : true
Is Palindrome?: false

How to check whether a passed string is palindrome or not in JavaScript ?

In this article, we are given a string, our task is to find string is palindrome or not. A palindrome is a series of numbers, strings, or letters that, when read from right to left and left to right, match each other exactly or produce the same series of characters. in simple words when number strings or characters are inverted and still provide the same outcome as the original numbers or characters. 

Example:

Input: "race"
Output: passed string is not a palindrome
Explanation: if we write "race" in reverse that is "ecar" it not 
matches with first string so it is not a palindrome.
Input: "hellolleh"
Output: passed string is palindrome.

These are the following methods by which we can check whether a passed string is palindrome or not:

Table of Content

  • By using a Naive Approach
  • By reversing the string
  • Uses the split(), reverse(), and join() Methods

Similar Reads

Approach 1: By using a Naive Approach

First, we iterate over a string in forward and backward directions.Check if all forward and backward character matches, and return true.If all forward and backward character does not matches, return false.If a return is true, it is a palindrome....

Approach 2: By reversing the string

Another approach is to reverse a string and check if the initial string matches the reverse string or not....

Approach 3: Uses the split(), reverse(), and join() Methods

Another approach, which is through the shortest approach, uses the split(), reverse(), and join() methods....

Using Array.every():

Using Array.every(), the approach iterates over the characters of the string from both ends simultaneously, comparing each pair. If all pairs match, it returns true, indicating the string is a palindrome; otherwise, false....