I have an API endpoint that returns a JSON response with a bunch of game ids. That response looks like this (and yes, it is heavily snipped).
{
"finished": [
{
"game_id": 8
},
{
"game_id": 9
},
{
"game_id": 11
}
],
"unfinished": [
{
"game_id": 12
},
{
"game_id": 13
}
]
}
What I want to achieve probably needs a bunch separate functions. But I want to search the array for a specific ID, that is user inputed. And depending if it is in the "finished" or "unfinished", return the value from that key.
Lets say that I want to search the array for ID of 13. That ID would be found in "unfinished". And if that is the case, I want to return the first ID in the "unfinished" array, ID 12.
If I would search the array for ID 9, that would be found in "finished", then return that ID (9).
If I would search the array for ID 12, that would be found in "unfinished", return the first ID from unfinished, ID 12.
Hope this makes sense.
I have been making some test just with searching the array, but no luck at all
const test = _.findKey(game_ids, function(o) { return o.game_id == 8; });