DEV Community

Discussion on: Sets in JavaScript

Collapse
 
jtenner profile image
jtenner

There is a lot of value when using a Set over an Array.

I learned yesterday that Set#has(item) performs an O(log n) algorithm to determine if the value exists in it. I was able to get a small speed increase in my javascript for it.

Good article!

Collapse
 
karataev profile image
Eugene Karataev

AFAIK, Set.has implementation in V8 is really fast - it has O(1) time complexity.

Collapse
 
jtenner profile image
jtenner

It's entirely possible I learned wrong! I took the statement at face value, knowing I couldn't verify it myself. If that's the case, then I'm really happy I use Set all the time now.