const pickRandom Target Style export const pickRandom = ({ from }) => from[Math.floor(Math.random() * from.length)] Picks a random element using named options. Target style API. Preferred for new code. Parametersoptions{ from: T[] } ReturnsT | undefined Exampleconst winner = pickRandom({ from: ['a', 'b', 'c'], })
const randomEl Legacy Style export const randomEl = (arr) => pickRandom({ from: arr }) Returns a random element from an array. Legacy API. Kept for older code and not the preferred choice for new code. ParametersarrT[] ReturnsT | undefined