getRandomValue
getRandomValue
(collection: Collection) => any
Return a random value in the collection.
If the collection is empty, undefined is returned.
getRandomValue(['a', 'b', 'c']) // is a, b or cgetRandomValue(['a', 'b', 'c']) // is a, b or cgetRandomValue(['a', 'b', 'c']) // is a, b or cgetRandomValue(['a', 'b', 'c']) // is a, b or cSometimes we want to pick a random value. Below, we're playing a game of Monopoly. Let's see who goes first.
const players = ['tom', 'ken', 'chris'] const firstPlayer = getRandomValue(players) console.log(firstPlayer) // is tom, ken or chrisconst players = ['tom', 'ken', 'chris'] const firstPlayer = getRandomValue(players) console.log(firstPlayer) // is tom, ken or chrisconst players = ['tom', 'ken', 'chris'] const firstPlayer = getRandomValue(players) console.log(firstPlayer) // is tom, ken or chrisconst players = ['tom', 'ken', 'chris'] const firstPlayer = getRandomValue(players) console.log(firstPlayer) // is tom, ken or chris