Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • 1
    You have the right idea conceptually but nothing prevents the function from taking the value first and the key second, which is precisely what a callback passed to Map.prototype.forEach must do because it receives (value, key) for each pair. Also, Map and Set also expose values methods that just return the values so it doesn't really answer the question. Commented Dec 18, 2016 at 13:25
  • 2
    @AluanHaddad OP was specifically asking why would you ever use the entries method, not asking which other methods Set and Map have. Commented Dec 18, 2016 at 17:38
  • 1
    That is true. However, it is still possible to write a function that works for both sets and maps without the entries method. Commented Dec 18, 2016 at 17:57
  • 1
    @AluanHaddad Even from the little experience with JS I have I really do not like altering prototypes of system types. Seems like monkey patching and you would need to alter prototypes of both Set and Map anyway. Personally I think the entries approach is leaner. Commented Dec 18, 2016 at 19:25
  • 1
    Why not just use the values method. I am not suggesting any prototype modifications. Commented Dec 18, 2016 at 19:30