Last active
August 25, 2022 20:14
-
-
Save Angelfire/1432fc08704b890920e6d15a0ad6563b to your computer and use it in GitHub Desktop.
Get multiple random items from array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getMultipleRandomItems = (arr, num) => { | |
const shuffled = [...arr].sort(() => 0.5 - Math.random()) | |
return shuffled.slice(0, num) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment