Languages

JavaScript - set of objects

0 points
Asked by:
Paris-Bateman
504

I'd like to have a set of objects that contains only unique objects. However, in my case I also need the keys to be objects.

I've read that Javascript casts property names to strings, so I guess I can't use set[object] = true.

Any ideas?

1 answer
0 points
Answered by:
Admin Dirask Community
4380

Since ES6 you can use native Set object type.

Note that a and b may have the same value but they are not the same objects in the operating memory (they have different references):

 

See also

  1. JavaScript - what is the difference between == and === operators?

References

  1. Set - JavaScript | MDN
0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join