javascript - Get next item in array using iterator using flags -


i trying obtain next object in object of objects (is drift). i'm looking through list of songs, , trying determine next song play. use flag playing check if song being played, index of next song , add id var called song

    var stop = false;     var song = null;     $.each(playlist,function(index, value){         if( !value.played ){             if( stop ){                 song = index;                 return false;             } else {                 if ( value.playing ) {                     playlist[index].playing = false;                     stop = true;                 }             }         }     });     playlist[song].playing = true;     playlist[song].played= true; 

here object looks like:

{  'hash1': {name:'test',played:true,playing:true},  'hash2': {name:'test2',played:true,playing:true} } 

the problem is, code ever plays first 2 songs in playlist. why this, or there better way achieve this?

thanks

p.s. here function on jsfiddle: http://jsfiddle.net/h1m7bx8g/

 $.each(playlist,function(index, value){         if( !value.played ){             if( stop ){                 song = index;                 return false;             } else {                 if ( !value.playing ) {                     playlist[index].playing = false;                     stop = true;                 }             }         }     }); 

outputs

(index):87 hash2 (index):87 hash3 (index):87 hash4 (index):87 hash5 (index):87 hash1 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -