JavaScript Index inside map() Function Last Updated : 13 Sep, 2024 Comments Improve Suggest changes Like Article Like Report In JavaScript, the map() function’s callback provides an optional second parameter, the index, representing the current element's position in the array. This index starts at 0 and increments for each element, allowing access to each item’s position during iteration.Syntax:array.map(function(currentelement, index, arrayobj) { // Returns the new value instead of the item});Parameters: The Index inside function accepts three parameters as mentioned above and described below:currentelement: The currentelement is a required argument in the map() which is the value of the current element.index: The index is an optional argument map() which is an array index of provided current element.arrayobj: The arrayobj is an optional argument in the map() which is the array object where the current element belongs. Example 1: In this example we use map() to iterate over the student array. It alerts each student's name and their position in the top 5 ranks, incrementing the index by 1 for display. JavaScript let student = ["Arun", "Arul", "Sujithra", "Jenifer", "Wilson"]; student.map((stud, index) => { alert("Hello... " + stud + "\n"); let index = index + 1; alert("Your Position in Top 5" + " Rank is " + index + "\n"); }); Output:Example: In this example we use map() to iterate over the webname array, displaying each element with a line break on the webpage and logging each element with its index to the console. JavaScript let webname = ["welcome", "to", "GeeksforGeeeks"]; webname.map((web, index) => { document.write(web + "<br>"); }); // check in console webname.map((web, index) => console.log(web, index)); Output:welcome 0to 1GeeksforGeeeks 2Supported Browsers: The browsers supported by the Index inside map() function are listed below:Google ChromeEdge FirefoxOperaSafari Comment More infoAdvertise with us Next Article JavaScript Index inside map() Function V VigneshKannan3 Follow Improve Article Tags : JavaScript Web Technologies javascript-functions javascript-map Similar Reads Interesting Facts About Map in JavaScript JavaScript Map is used to store the data of key-value pairs. It can be used to store any type of value including objects and primitive data types. It is iterable which is the main reason we can manipulate it according to the need.Map Internally Uses Hash TableJavaSctipt Map internally uses Hashing t 4 min read JavaScript Map entries() Method JavaScript Map.entries() method is used for returning an iterator object which contains all the [key, value] pairs of each element of the map. It returns the [key, value] pairs of all the elements of a map in the order of their insertion. The Map.entries() method does not require any argument to be 4 min read JavaScript Map() Constructor The Map() constructor is used to create Map objects in JavaScript. The map is a data structure that stores elements as a key, value pair.Syntax:new Map()new Map(iterable)Parameters:iterable: An iterable object used for iterating through elements, stored as a key, value pair.Return value:A new Map ob 3 min read JavaScript Map get() Method The Map.get() method in JavaScript is a convenient way to retrieve the value associated with a specific key in a Map object. A Map in JavaScript allows you to store key-value pairs where keys can be of any data type, making it more useful compared to objects, which only allow strings and symbols as 3 min read How to get the Value by a Key in JavaScript Map? JavaScript Map is a powerful data structure that provides a convenient way to store key-value pairs and retrieve values based on keys. This can be especially useful when we need to associate specific data with unique identifiers or keys.Different Approaches to Get the Value by a Key in JavaScript Ma 3 min read Like