My goal is to find if the value is in JavaScript array, but very efficiently. I understand that inarray? check will usually execute in O(n) where n is the length of an array because we have to traverse through every variable in the array. But hashmap will always return us the value in 0(1) (at least from my understanding)
So what if instead of traversing an array we created an key -> variable association, where the key is identical to the value and just tried getting the element by key. If it exists, then we return true, if it is 'undefined'
, we return false?
Has anyone ever done this before and is this even feasible in terms of javascript language?