I have a JSON object like this:
"time1": {
    "item1": "val1",
    "item2": "val2"
},
"time2": {
    "item1": "val3",
    "item2": "val4"
}
...
The value of time* is the new Date() value in milliseconds, so the sequence of the time* value is sorted.
Now I have to search an item by time, if the key doesn't exist I have to take the nearest value. I have thousands of entries in the object and I'm thinking about the binary search but I have no idea about how to do.
I can't use the classic way middle = (right+left)/2 because the middle value could be undefined.
I can't use binary tree because I have a defined structure I can't change.
Thanks
 
     
     
     
    