If you're just trying to check whether a value is included in a collection, It would be more appropriate to use a Set
, As Arrays
can have duplicate values whereas Sets
cannot. Also, Replacing array.includes
with set.has
improves the performance from O(n2) to O(n). This will be useful when you have to look up multiple values for the same Set. so if you're just going to look up a single value, there's no benefit to use set.has
, you can just use an array.includes
.
Created a jsbench demo, You can run this to check the performance.
Screenshot of the test execution :