Javascript describes the syntax of a map method as:
arr.map (callback [, thisArg])
Parameters
- callback is a function that creates an element of a new array using three arguments:
- currentValue - the current element is processed in the array.
- index - the index of the current element being processed in the array. Array
- An array map is provided.
- thisArg is the value to use when executing the callback.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
I can write a JS function that will capitalize the first letter of each word in an array of strings as follows:
capyyIt(['john', 'nelson mandela', 'james booth'])
function capyyIt(names) {
return names.map(function capIt(curr) { return curr[0].toUpperCase() + curr.slice(1).toLowerCase(); });
}
user1096557