The below function will display a random object from the array, passing the index number to setIndex(index). I want to display a random and unique object. How do I achieve this?
const length = array.length
const randomScenario = () => {
const index = Math.floor(Math.random() * length);
setIndex(index);
}
onClick={randomScenario}to your button?const [index, setIndex] = React.useState(0); and thenconst item = array[index]should work no?