This question already has an answer here:
if I need to find an object in a Set. The set does not contain a natural key to use as an index, so I can't use Map. There are several different types of predicates used to search the Set. It seems inefficient to do
const items = Array.from( mySet )
const found = items.find( item => someTest( item ) )
Unless there's black magic in the optimiser, it seems like it will enumerate twice. I know it exposes an iterator interface, but the Array.prototype.find interface is much more concise than using a for...of loop with a break statement.
Is there a better way?
Use a Map instead with the id (unique identifier) as the key:
You have has method on Set to find existence of value.
Sets implement the iterator interface, so you should be able to iterate them looking for your particular item. It will not be as nice and declarative as using a find with an hig order function, with will be much more efficient. You can of course encapsulate that logic to make it much nicer