How to use Array map() Method In Javascript

The array.map() method creates an array by calling a specific function on each item in the parent array and it does not change the value or element of the array.

Syntax:  

array.map(function(value, index, array){
}[ThisArgument]);

Parameters: This method accepts three parameters as mentioned above and described below: 

  • value: This is the current value being processed by the function.
  • index: The item index is the index of the current element which was being processed by the function.
  • array: The array on which the .map() function was called.

Example: This example performs a sum operation on every element of the array and displays output. It does not change the values of the original array.

Javascript




let numArray = [1, 2, 3, 4];
let numArray2 = numArray.map(multiplyFunction);
 
console.log(numArray2);
 
function multiplyFunction(value, index, array) {
    return value + 100;
}


Output

[ 101, 102, 103, 104 ]


Similar Articles 

All these are the array iterator functions.



JavaScript Array Iteration Methods

JavaScript Array iteration methods perform some operation on each element of an array. Array iteration means accessing each element of an array.

There are some examples of Array iteration methods are given below:

Similar Reads

Method 1: Using Array forEach() Method

The array.forEach() method calls the provided function (a callback function) once for each element of the array. The provided function is user-defined, it can perform any kind of operation on an array....

Method 2: Using Array some() Method

...

Method 3: Using Array map() Method

The array.some() method checks whether at least one of the elements of the array satisfies the condition checked by the argument function....