On my page I’m making ajax-request to get data from server. The data is list of JSON objects..
Every object has name, description and datetime. How can I get the object which is the closer to my real data in browser…
Example:
$(json).each(
function(i) {
alert(json.datetime)
//here have to be some algorithm to comparing the time with my current time instead of alert..
});
It sounds like you simply need to loop over each element and compare the date times, storing the current element if it’s closer than the last element you compared.
This assumes your
jsonarray contains at least one element, and that yourdatetimefields are standard Unix timestamps.