使用标志使用迭代器获取数组中的下一项

Get next item in array using iterator using flags

我正在尝试获取对象对象中的下一个对象(你明白我的意思了吗)。我正在查看歌曲列表,并试图确定要播放的下一首歌曲。我使用标志 playing 检查歌曲是否正在播放,然后我获取下一首歌曲的索引并将 id 添加到名为 song

的 var
    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;

对象的外观如下:

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

问题是,我的代码只播放播放列表中的前两首歌曲。为什么会这样,或者有没有更好的方法来实现?

谢谢

p.s。这里的函数在 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;
                }
            }
        }
    });

产出

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