Find a palindrome using Array methods
let str = "civic"; let strReverse = str.split("").reverse().join(""); if (str === strReverse) { console.log("The string is a palindrome"); } else { console.log("NOT a palindrome"); }
Source: sebhastian.com
palindromes array number
function isPalindrome(N) { str = " " + N; len = str.length; for (var i = 0; i < len / 2; i++) { if (str[i] != str[len - 1 - i]) return false; } return true; } function isPalinArray(arr,n) { var counter = 0; for (var i = 0; i < n; i++) { ans = isPalindrome(arr[i]); if (ans == true) counter++; } console.log("Number of Palindromes in the array:" + counter); } arr = [123, 121]; n = arr.length; res = isPalinArray(arr, n);