Given an array, return a random value from it.
MIT License
TypeScript module with type definition support by default. Also works with other JavaScript projects.
Given an array, return a random value from it.
An array of elements must output a random value.
$ npm i random-from-array
import randomFromArray from 'random-from-array'
randomFromArray(['bossa nova', 'jazz', 'rock']) // one of: 'bossa nova' or 'jazz' or 'rock'
// also works with an array of objects
const arrayOfObj = [
{ value: 'bossa nova' },
{ value: 'jazz' },
{ value: 'rock' }
]
randomFromArray(arrayOfObj) // one of: { value: 'bossa nova' } or { value: 'jazz' } or { value: 'rock' }
random-from-array Cezar Augusto. Released under the MIT License.