Javascript How do I split a JSON array, find the max value out of the numbers, then grab the name to go with it? -


i have external json file array contains information need, can't life of me figure out how split it.

  {     "video": "incoming2.mp4",     "description": "updated every 30 minutes: - created 2015-07-07 14:45:29 est",     "title": "304 angstrom last 3 days",     "timestamp": "2015-07-07 14:45:29 est",     "sort": ["20150707144529", "incoming2.mp4"],     "thumb": "thumb/incoming2.png"   }, 

here small part of json file, place should direct attention "sort": ["20150707144529", "incoming2.mp4"],, want create array in javascript using of these within file, , splitting them own data within array this: arrayname[0] "20150707144529" while arrayname[1] "incoming2.mp4". then, after split, want find highest value based on first number within sort, , grab file name directly after , store in variable.

(ps: know i'm kinda bad @ wording things, if need me clarify i'm asking, ask me so)

edit:

how i'm calling json file:

$(document).ready(function vidtitle() {     $.getjson("sun.json", function(json1) {         //json stuff here     }); }); 

edit 2:

here (kinda sort of not really) full(-ish) json file

[   {     "video": "incoming.mp4",     "description": "updated every 30 minutes: - created 2015-07-07 14:45:24 est",     "title": "193 angstrom last 3 days",     "timestamp": "2015-07-07 14:45:24 est",     "sort": ["20150707144524", "incoming.mp4"],     "thumb": "thumb/incoming.png"   },   {     "video": "incoming2.mp4",     "description": "updated every 30 minutes: - created 2015-07-07 14:45:29 est",     "title": "304 angstrom last 3 days",     "timestamp": "2015-07-07 14:45:29 est",     "sort": ["20150707144529", "incoming2.mp4"],     "thumb": "thumb/incoming2.png"   },   {     "video": "incoming3.mp4",     "description": "updated every 30 minutes: - created 2015-07-07 14:47:35 est",     "title": "171 angstrom last 3 days",     "timestamp": "2015-07-07 14:47:35 est",     "sort": ["20150707144735", "incoming3.mp4"],     "thumb": "thumb/incoming3.png"   }   //basically, bunch more of above different data ] 

here's simplified example: https://jsfiddle.net/qaf1q2ao/

i removed of properties in json don't care about. threw more sample data in array keyed data. searches highest sort value each object in data array, keeping track of index of current maximum. once finished loop, maxindex contains index array contains highest sort value.

$.getjson('sun.json', function(json) {     var max = 0;     var maxindex = 0;      (var index = 0; index < json.length; index++) {         var val = parseint(json[index].sort[0]);         if (val > max) {             max = val;             maxindex = index;         }     }      alert('highest ' + json[maxindex].sort[1]); }); 

output

highest incoming2.mp4


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -