JavaScript Array map() Method Last Updated : 12 Mar, 2025 Comments Improve Suggest changes Like Article Like Report The map() method is an ES5 feature that creates a new array by applying a function to each element of the original array. It skips empty elements and does not modify the original array. JavaScript const a = [1, 2, 3, 4]; // Use map to create a new array with elements doubled const b = a.map(x => x * 2); console.log(b); Output[ 2, 4, 6, 8 ] Syntaxarr.map((element, index, array) => { /* … */ })Parameters element: It is a required parameter and holds the current element's value.index: It is an optional parameter and it holds the index of the current element.arr: It is an optional parameter and it holds the array.Return ValueIt returns a new array and the arrays' elements result from the callback function. Example 1: Here, we are using the map() method to create a new array containing the square roots of each number in the original array. JavaScript const a = [1, 4, 9, 16, 25]; const sr = a.map(num => Math.sqrt(num)); console.log(sr); Output[ 1, 2, 3, 4, 5 ] Example 2: This example uses the array map() method and returns the square of the array element. JavaScript let a = [2, 5, 6, 3, 8, 9]; // Using map to transform elements let res = a.map(function (val, index) { return { key: index, value: val * val }; }) console.log(res) Output[ { key: 0, value: 4 }, { key: 1, value: 25 }, { key: 2, value: 36 }, { key: 3, value: 9 }, { key: 4, value: 64 }, { key: 5, value: 81 } ] Example 3: This example uses the array map() method to concatenate the character 'A' with every character of the name. JavaScript let s = "Geeks"; // New array of character and names // concatenated with 'A' let res = Array.prototype.map.call(s, function (item) { return item + 'A'; }) console.log(res) Output[ 'GA', 'eA', 'eA', 'kA', 'sA' ] Passing a method as parameter to map()The parseInt() function converts strings to integers. When used with map(), it converts each element of an array of strings to integers. This explains that the map function can take another function as a callback function that has one parameter and another optional parameter. Note: We are converting string to integer so that Example: Here, we are using parseint() with map() function. JavaScript const a = ['10', '20', '30']; const b = a.map(s => parseInt(s)); console.log(b); Output[ 10, 20, 30 ] Recommended Links JavaScript Array Complete reference JavaScript Tutorial JavaScript Examples JavaScript Cheat Sheet-A Basic guide to JavaScript. Comment More infoAdvertise with us P Pankaj_Singh Follow Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-Methods Similar Reads JavaScript Array() Constructor The Array() constructor is used to create Array objects and the array constructor can be called with or without a new keyword, both can create a new Array.Syntax:new Array(Value1, Value2, ...);new Array(ArrayLength);Array(Value1, Value2, ...);Array(ArrayLength);Parameters: ValueN: An array initializ 2 min read JavaScript Array constructor Property The JavaScript Array constructor property is used to return the constructor function for an array object. It only returns the reference of the function and does not return the name of the function. In JavaScript arrays, it returns the function Array(){ [native code] }.Syntax: array.constructorReturn 2 min read JavaScript Array length JavaScript array length property is used to set or return the number of elements in an array. JavaScriptlet a = ["js", "html", "gfg"]; console.log(a.length);Output3 Setting the Length of an ArrayThe length property can also be used to set the length of an array. It allows you to truncate or extend t 2 min read JavaScript Array from() Method The JavaScript Array from() method returns an Array object from any object with a length property or an iterable object. Syntax : Array.from(object, mapFunction, thisValue)Parameters:object: This Parameter is required to specify the object to convert to an array.mapFunction: This Parameter specifies 3 min read JavaScript Array isArray() Method The isArray() method in JavaScript is used to determine whether a given value is an array or not. This method returns true if the argument passed is an array else it returns false.Syntax:Array.isArray(obj);Parameters:obj: This parameter holds the object that will be tested.Return value:This function 3 min read JavaScript Array of() Method The Javascript array.of() method is an inbuilt method in JavaScript that creates a new array instance with variables present as the argument of the method.Syntax:Array.of(element0, element1, ....)Parameters: Parameters present are element0, element1, .... which are basically an element for which the 2 min read Javascript Array at() Method The JavaScript Array at() method takes an integer value (index) as a parameter and returns the element of that index. It allows positive and negative integers. For the negative integer, it counts back from the last element in the array.Syntax:at(index);Parameter: This method accepts one parameter th 3 min read JavaScript Array concat() Method The concat() method concatenates (joins) two or more arrays. It returns a new array, containing the joined arrays. This method is useful for combining arrays without modifying the originals.Syntax:let newArray1 = oldArray.concat()let newArray2 = oldArray.concat(value0)let newArray3 = oldArray.concat 3 min read JavaScript Array copyWithin() Method The Javascript Array.copyWithin() method considers an array first and then copies part of an array to the same array itself and returns it, without modifying its size but yet the modified data whatever user wishes to have in another's place i.e, copies array element of an array within the same array 3 min read JavaScript Array entries() Method The entries() method in JavaScript is used to create an iterator that returns key/value pairs for each index in the array.It allows iterating over arrays and accessing both the index and value of each element sequentially.Syntax:array.entries()Parameters:This method does not accept any parameters.Re 3 min read Like