Skip to content

Map entries() JavaScript | Method

  • by

Use the JavaScript Map entries() method to get a new map iterator. This method returns a new iterator object that contains the [key, value] pairs for each element in the Map object in insertion order.

obj.entries()  

Map entries JavaScript

Simple example code.

<!DOCTYPE html>
<html>
<body>
  <script >
    const mapObj = new Map();

    mapObj.set('0', 'foo');
    mapObj.set(1, 'bar');

    const iterator = mapObj.entries();
    console.log(iterator)

    console.log(iterator.next().value);
    console.log(iterator.next().value);
  </script>
</body>
</html>

Output:

Map entries JavaScript method

More example

var myObject = { 'a': 1, 'b': 2, 'c': 3 };

Object.keys(myObject).map(function(key, index) {
  myObject[key] *= 2;
});

console.log(myObject);

Output: { a: 2, b: 4, c: 6 }

for key value in object JavaScript

for (const [key, value] of Object.entries(object1)) {
  console.log(`${key}: ${value}`);
}

Do comment if you have any doubts or suggestions on this Js Map entries tutorial.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading