DEV Community

Dennis Mathenge
Dennis Mathenge

Posted on


#Javascript: Using the function.

When working with JavaScript arrays, you might want to create a new array with the results of calling a provided function on every element in the previous/original array.

JavaScript has a very nifty function called that you can use to do this. accepts a callback function as a parameter.

The callback function produces an element of the new Array and takes three arguments:

  • currentValue - This is the current element being processed in the array.
  • index (optional) - This is the index of the current element being processed in the array.
  • array (optional) - The original array that map was called upon.
  • thisArg (optional) - Value that you can use as this when executing the callback

Example usage:

const names = ['mike', 'john', 'anne'];
const namesUppercase = => name.toUpperCase());
namesUppercase = ["MIKE", "JOHN", "ANNE"]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)