JavaScript Array map() methodThe JavaScript array map() method calls the specified function for every array element and returns the new array. This method doesn't change the original array. SyntaxThe map() method is represented by the following syntax: Parametercallback - It represents the function that produces the new array. currentvalue - The current element of array. index - It is optional. The index of current element. arr - It is optional. The array on which map() method operated. thisArg - It is optional. The value to use as this while executing callback. ReturnA new array whose each element generate from the result of a callback function. JavaScript Array map() method exampleLet's see some examples of map() method. Example 1Here, map() method returns the round of given elements to the nearest integer. Test it NowOutput: 2,4,5 Example 2Here, map() method returns every element of given array by multiplying it by 3. Test it NowOutput: 6,12,18 Next TopicJavaScript Array |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India