Skip to content

Instantly share code, notes, and snippets.

@mflorida
Last active December 4, 2024 03:57
Show Gist options
  • Save mflorida/822f04f0a1f4534b26c8e13c730be103 to your computer and use it in GitHub Desktop.
Save mflorida/822f04f0a1f4534b26c8e13c730be103 to your computer and use it in GitHub Desktop.
Pick random item from array
/**
* Pick random item from an iterable object
* @param {string|Array|Map|Iterable} items
* @returns {*}
*/
export function pickRandom(items) {
return [...items][Math.floor(Math.random() * (items.length))];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment