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; } |
[ 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:
- Using Array forEach() Method
- Using Array some() Method
- Using Array map() Method