I'm having a hard time finding a dupe of this question, but I assume it's been asked before....
If I add three items to a Set
:
var s = new Set();
undefined
s.add(1); s.add(2); s.add(3);
Set(3) {1, 2, 3}
... How can I find out the index of an item?
There is no indexOf
method for Set
and I'm not sure if iterating over the Set is the best way. I've tried using the forEach
API but can neither break
nor return
from this function:
if (s.size < cells.length) {
var count = 0;
s.forEach(function (value) {
if (cell.id.slice(0, -5) == value) {
break; //return fails here too...
}
count ++;
});
return count;
}