Currently experimenting with json objects in javascript and looking for assistance with a specific issue
The json file I have consists of hash objects containing an ID key and an array value [ ipaddress, timestamp, url]
For example:
{"output":
{
"1":["10.0.0.1","2012-07-11T11:41:42+01:00","http://myurl.com"],
"2":["10.0.0.1","2012-07-11T11:45:42+01:00","http://myurl2.com"],
"3":["192.168.1.1","2012-07-11T11:41:47+01:00","http://myurl3.com"]
}
}
I am interested in sorting the contents of these arrays
Specifically, I want to extract the highest timestamp for each IP address from the json data
Based on the example above, the desired output would be:
10.0.0.1 - http://myurl2.com
192.168.1.1 - http://myurl3.com
Currently, I have a basic function that displays the raw data in a div, but I believe handling the arrays could be improved
var displayOutput = function(data){
var container = $("#fragment-1");
var body = “”;
$.each(data.output, function(key, val) {
var arr = val.toString().split(",");
body = body + arr[0]+ ' - ' + arr[1]) + ' - ' + arr[2]
});
container.html(body);
};