Created
August 30, 2022 17:48
-
-
Save Angelfire/826f8e441549234015fe92a0ce68bf16 to your computer and use it in GitHub Desktop.
Get x random items from an 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
function getRandomArrayItems(list, neededElements) { | |
const result = [] | |
for (let i = 0; i < neededElements; i++) { | |
result.push(list[Math.floor(Math.random() * list.length)]) | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment