JSFiddle - React, Tailwind, and code Playground

JavaScript

var playlist = {
  "hash1": {
    "id": 5,
    "name": "title",
    "score": 0,
    "playing": false,
    "played": false
  },
  "hash2": {
    "id": 6,
    "name": "title",
    "playing": false,
    "played": false
  },
  "hash3": {
    "id": 4,
    "name": "title",
    "playing": false,
    "played": false
  },
  "hash4": {
    "id": 1,
    "name": "title",
    "playing": false,
    "played": false
  },
  "hash5": {
    "id": 9,
    "name": "title",
    "playing": false,
    "played": false
  },
 }; 

function getNextItem()
{
    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;
                }
            }
        }
    });
    
    if( song === null ){
        song = Object.keys(playlist)[0]
    }
    
    playlist[song].playing = true;
    playlist[song].played = true;
    
    if( stop === false ){
        $.each(playlist,function(index, value) {
            playlist[index].played = false;
        });
    }
    
    console.log(song);
  //return song;
}


getNextItem();
getNextItem();
getNextItem();
getNextItem();
getNextItem();
getNextItem();