OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why iteration over Map keys with forEach works in browser and fails in Node.js environment?

  • Thread starter Thread starter Noob
  • Start date Start date
N

Noob

Guest
Here is the code:

Code:
let map = new Map()
map.set('a', 1)
map.keys().forEach(key=>console.log(key))

When I run it in the browser console, I get the keys logged as expected.

When I run it in Node.js environment(v18.18.0) I get this error:

Code:
Uncaught TypeError: map.keys(...).forEach is not a function

Any idea why it's happening?

<p>Here is the code:</p>
<pre><code>let map = new Map()
map.set('a', 1)
map.keys().forEach(key=>console.log(key))
</code></pre>
<p>When I run it in the browser console, I get the keys logged as expected.</p>
<p>When I run it in Node.js environment(v18.18.0) I get this error:</p>
<pre><code>Uncaught TypeError: map.keys(...).forEach is not a function
</code></pre>
<p>Any idea why it's happening?</p>
 

Latest posts

G
Replies
0
Views
1
Gamal Othman
G
Top