English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Array map() Method

 JavaScript Array Object

map()The method creates a new array and calls the provided function for each element in the array.

map()The method executes the callback function once for each array index.

Note : The map() method does not change the original array.

Syntax :

array.map(callback, thisArg)
var nums1 = [1 5 20, 14 55 16]
var nums2 = nums1.map(twice);
function twice(element) {
   return (element * 2);
}
Test see‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the map() method:

Method
map()Is1.5IsIs9

Parameter Value

ParameterDescription
callback
A function that is run for each element in the array.
Function Parameters:
  • element(Required)-The current element being processed in the array

  • index(Optional)-The index of the current element being processed in the array

  • array(Optional)- Called on the arrayMapping

thisArg(Optional) Executecallbackis used asThisObject

Technical Details

Return Value:A new array where each element is the result of a callback function
JavaScript Version:ECMAScript 5

More Examples

This example uses a number array and creates a new array containing the square roots of the numbers in the array:

var nums1 = [4 9 16 25]
var nums2 = nums1.map(Math.sqrt);
Test see‹/›

 JavaScript Array Object