CodesJava

Easy learning with example program codes

JavaScript Array map() method

The JavaScript array map() method is used to call a particular function for each element of the array and returns the new array.

Note: Original array will not be changed. It will return a new array.

Syntax:

array.map (callback(currentvalue,index,arr),thisArg)

Parameters:
callback: It represents the method to test the condition. It is required.
currentValue: It represents array’s current element. It is required.
index: Current element index. It is optional.
arr: It represents the array on which every() method to be invoked. It is optional.
thisArg: It is used as this keyword while executing callback. It is optional.

Returns:
A new array.

Example:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>  
var a = ["GOLD","SILVER","DIAMOND","RUBY","PLATINUM"]	 
var result=a.map(x=> x + " Jewel ");  
document.writeln(result);
</script>  
</body>
</html>

Output:

GOLD Jewel ,SILVER Jewel ,DIAMOND Jewel ,RUBY Jewel ,PLATINUM Jewel
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status