in Python, if you use set() and in
operator, you can see whether an exists in a set in O(1). However, in javascript, is it possible to do the same with the same time complexity? I have usually done
var arr = [1,2,3,4,5];
if (arr.indexOf(3) != -1) return true; // element exists!
without being really sure about its efficiency.