For a basic hello world style example of the lodash map method there is starting out with a simple array of numbers as a source array. I can then pass this simple source array as the first argument for the lodahs map method, followed by a function that will be called for each element in the source array where the return value will be the value of the corresponding element in the new array that will be returned by lodash map.
So the lodash map method is a great way to create a new array, based off of the values of another source array, without mutating the source array in place.
The map method in lodash is a so called collection method, this means that the lodash map method can be used on plain old objects as well as Arrays. So then I can give just a plain old object as the source object for the lodash map method, and the values of that object will be used to create the new array that will be returned by lodahs map.
For a more advanced example of _.map in action, say I have a complex object that has nested objects inside of it, and I want to toggle a boolean value for each object, and flatten everything out into an array. I can call _.map recursively on objects, and arrays. Other lodash methods like _.isArray, and _.flatten can also be used in the process.
The Array map method will create a new array with what is returned by a given method that will be called for each element in the array. The first argument in the method that is passed is the current value of an element in the array, and the return keyword is used to return what will become the new value for the element in the array.
Now that we have a basic example of the native array map meth9d out of the way lets take a look at what can be done with the lodash equivalent of array map.