GitHub 6521★

Get a random item from an array

JavaScript version

const randomItem = (arr) => arr[(Math.random() * arr.length) | 0];

TypeScript version

const randomItem = <T,_>(arr: T[]): T => arr[(Math.random() * arr.length) | 0];
Follow me on and to get more useful contents.