JavaScript Map
- Map can have keys of any data type, including objects, functions, and primitive values.
- Map keys are ordered based on their insertion order.
- Maps have built-in methods for iteration, such as
forEach
,keys
,values
, andentries
.
Syntax:
map((element, index, array) => { /* … */ })
Parameters:
- element: It is a required parameter and it holds the value of the current element.
- 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.
Map vs Object in JavaScript
In JavaScript, both map and object stores the key-value pairs but differ on some features and use cases.
Contact Us