[Solved] Javascript – What’s faster: a linear list search or getting an object value? [closed]


An object lookup will on average be much faster when trying to find a random element, especially when you are searching through a large number of items. This is because the underlying algorithm to do so is a B-tree search which has a time complexity of O(log n) and allows it to quickly look up an items membership without having to check it against each element in the object.

This is opposed to when searching in an array you must check each element before deciding if is not in the array which has a linear time complexity of O(n).

Here is the benchmark showing object lookup is faster: http://jsperf.com/array-vs-objv2/6

solved Javascript – What’s faster: a linear list search or getting an object value? [closed]