I am using a loop to add to a Set in JavaScript. Something like:
let mySet = new Set();
$('li').each(function() {
mySet.add($(this).text());
})
This works fine. However, I wanted to see if I could leverage .add()
to tell me if the item was successfully added or not, without iterating through the set looking for a match again.
Does anyone know if this is possible?