In the official JSON documentation
An object is an unordered set of name / value pairs. An object begins with {(left curly brace) and ends with} (right curly brace). Each name followed by: (colon), and name / value pairs are separated, (comma).
Note I am new to Javascript and the JSON name itself (Javascript), I assume that the objects in Javascript are the same as JSON. Please correct me if I am wrong.
From the above definition, it seems that Javascript objects are most likely implemented using either a hash map, or with a BST, or with some similar data structure.
But when I insert key value pairs into the Node shell, they are inserted sequentially. This is what I tried in node shell
> var a = {} undefined > a['k1'] = 'a1' 'a1' > a['k3'] = 'a3' 'a3' > a['k2'] = 'a2' 'a2' > a['k4'] = 'a4' 'a4' > a['k5'] = 'a5' 'a5' > a { k1: 'a1', k3: 'a3', k2: 'a2', k4: 'a4', k5: 'a5' }
Now, when printing a pairs of key values ββare returned in the same order as the inserts. So my questions are:
- Get a quick key search? I mean complexity O (log (n)) or better.
- If JSON does not use a data structure such as BST, hashmap, or some similar DS, then how exactly do JSON objects lie in memory?
Update So, what about Javascript objects. Can someone comment on the basic implementation of Javascript objects.
source share