jquery - Javascript: how to handle a next item in json - playlist -


I have an application that creates a playlist of the video and returns them in Jason format, the video ID "key "And then the Video ID is attached to it, the video ID is not sequential," 1234 "," 4234 "," 123 "," 5454 "are possible IDs, among others.

I have a button to switch to the next video, the problem I do not know how to get the next item in the array until I loop through the whole array which seems very incompatible. I am using jQuery, if any function is available that would be excellent.

A summary of my question: How do I select the next item in an array using jQuery / Javascript efficiently?

If you are in control of part of creating JSON, then I will change it to actually return an array. If not, I would probably create a loop with my Jason data from my object with my object:

  var list, name; List = []; For (name in obj) {list.push ({key: name, value: obj [name}}); }  

Then you can walk through a numerical index. Now, there I have named the name / key if you do not need it, if you just need the value, then the array can catch the values ​​directly. Edit Once, deserialized, that will result in an object result with video [1234 "," 4234 "," 123 "," 5454 "]

Which is an array then you can loop through the array with a numerical index, so the "Next video" function will be:

  function showNextVideo (video, index) {++ index; If (index> = video.lamp) {index = 0; } Show video (video [index]); }  

You can read more about JSON here:


Comments