
Whereas only looks into the immediate hash-table. In looks up the immediate hash-table of the object and then recursively searches the hash-tables of the prototypes of this objects. It is a hierarchical structure of hash-tables, each containing properties of objects. One such features the prototype, the link between the object and it's prototype. It is related to the fact that all things in JavaScript are objects, and thus they have some object-y features. The difference between the two needs further explaining. However, if you wanted to look for the key, then there are two functions: in and. There is a standard function for doing it:. This means that if you wanted to find a string value inside an int-hash-table, then it would be an O(n) operation. So, when you say Array in JavaScript context it is understood as int-hash-table, and all the asymptotic complexity associated with it.

The downside is the complexity of implementation. This is why function in JavaScript is very fast. For example, deleting an element from int-hash-table is an O(1) operation, while deleting an element from array is an O(n) operation (because you need to copy the rest of the elements into the new array). These perform similarly to arrays, but they differ in certain ways. The standard Array function constructs hash-tables (I will call these integer hash-tables, or int-hash-tables) where the keys are integers in addition to string keys. For example, Underscore provides one (it calls it indexOf).įundamentally, JavaScript has only hash-tables. You can, of course, roll your own, but there are many libraries that provide one already. There isn't a built in function for value lookup in hash-tables. If you want the fastest value lookup, use for Array. If you want the same, but for the objects with extensive inheritance chain, use

If you want fastest key lookup for objects with short prototype inheritance chain use in. First of all, there is some fundamental confusion here about what data structures are available in JavaScript.
