Javascript map method on array of string elements
08:53 21 Jan 2016

I am trying to understand how to implement the map method (rather than using a for loop) to check a string for palindromes and return boolean values for whether the mapped array elements reversed are the same as the original array elements. I cannot seem to understand the syntax of the map method. How do I get the map to function on each element in the original array? What is the value? Here is my working code, which is only logging a value of undefined:

function palindromeChecker(string) {
    var myString = string.toLowerCase();
    var myArray = myString.split(" ");
    var newArray = myArray.map(function (item) {
        item.split("").reverse().join("");
        return newArray === myArray;
    });
}

console.log(palindromeChecker("What pop did dad Drink today"));

Here is a link to the fiddle: https://jsfiddle.net/minditorrey/3s6uqxrh/1/

There is one related question here:

Javascript array map method callback parameters

but it doesn't answer my confusion about the syntax of the map method when using it to perform a function on an array of strings.

javascript arrays dictionary