map()
creates a new array from calling a function for
every array element.
map()
does not execute the function for empty elements.
map()
does not change the original array.
class = "table table-striped table-bordered"
Parameter | Description |
function() |
Required. A function to be run for each array element. |
currentValue |
Required. The value of the current element. |
index |
Optional. The index of the current element. |
arr |
Optional. The array of the current element. |
thisValue |
Optional. Default value undefined .A value passed to the function to be used as its this value.
|
Type | Description |
An array | The results of a function for each array element. |
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var ary = [11,4,9,16];
var b = ary.map(test);
document.write(b);
function test(x){
return x * 10;
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var ary = [
{fname : "Yahoo" , lname : "Baba"},
{fname : "Rahul" , lname : "Kumar"},
{fname : "Karan" , lname : "Sharma"},
];
var b = ary.map(test);
document.write(b);
function test(x){
return x.fname + " " + x.lname;
}
</script>
</head>
<body>
</body>
</html>