JSFiddle - React, Tailwind, and code Playground

JavaScript

myArray = JSON.parse(sessionStorage.getItem("array"));

// If array does not exist in sessionStorage, set it
if (myArray === null || myArray.length === 0) {
    sessionStorage.setItem('array', JSON.stringify(["apple", "orange", "banana"]));

    // If array exists in sessionStorage, use it to get random item and empty it from array
} else {

    //get random index of item to remove
    var randomIndex = Math.floor(Math.random() * myArray.length);

    //remove the item at that index
    console.log(myArray.splice(randomIndex, 1)); //this returns an array containing the removed item, so you can capture it if you like
    console.log(myArray);
    sessionStorage.setItem('array', JSON.stringify(myArray));
}