Hey @toby-steed thats the very standard approch and might not work in all cases.
However, here’s another method I’ve tried that’s pretty fun, it shuffles the array randomly and then picks the first item. It’s like mixing a deck of cards before drawing one! ![]()
const items = [523, 3452, 334, 31, 5346];
const [randomItem] = items.sort(() => 0.5 - Math.random());
console.log(randomItem);
This works by sorting the array with a random comparator, so the order gets mixed up every time, and then you just grab the first element. It’s neat for small arrays when you want to add a little randomness flair!