JavaScript Array map() Method
You are Here:
JavaScript Array map() Method
The map()
method creates a new array with the results of calling a provided function on every element in the calling array.
Note: This method does not alter the original array.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
var myNumber = [1, 2, 3, 4, 5, 6, 7];
var myMap = [];
var multiValue = 10;
function multiply(value){
return e = value * multiValue;
}
myMap = myNumber.map(multiply);
document.write("myNumber array = " +myNumber);
document.write("<br>myMap array = " +myMap);
</script>
</body>
</html>
Syntax
Array.map(function(value, index, arr), thisArg);
//or
Array.map(functionName);
Parameter Values
Value | Type | Explanation |
---|---|---|
function(value, index, arr) | Required | Function to test for each element in an array. Value - Specifies a value or element in an array. index - Specifies the index of a value or element in an array. arr - Specifies the whole array. |
thisArg | Optional | Specifies a value against which each element in an array is tested. |
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
var myNumber = [1, 2, 3, 4, 5, 6, 7];
var myMap = [];
function multiply(value, index, arr){
return e = value * this;
}
myMap = myNumber.map(multiply, 10);
document.write("myNumber array = " +myNumber);
document.write("<br>myMap array = " +myMap);
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.