![]() |
VOOZH | about |
JavaScriptMap.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 passed and returns an iterator object of the map.
mapObj.entries();Example 1: In this example, a map object "myMap" has been created with three [key, value] pairs, and an iterator object "iterator_obj" method is created which uses Map. entries() method to return the [key, value] pairs of all the elements of a map in the order of their insertion.
[ 0, 'geeksforgeeks' ] [ 1, 'is an online portal' ] [ 2, 'for geeks' ]
Example 2: In this example, a map object "myMap" has been created with three [key, value] pairs, and an iterator object "iterator_obj" method is created which uses Map. entries() method to return the [key, value] pairs of all the elements of a map in the order of their insertion.
[ 0, 'Maps' ] [ 1, 'in JavaScript' ]
Whenever we want to get all the [key, value] pairs of each element of a map using an iterator object, we use the Map.entries() method.