random-element-selector

1.0.2 • Public • Published

Random element selector

random-element-selector returns one randomly chosen element from the passed-in array.

Setup

Install the package:

npm install random-element-selector

Usage

import randomElement from 'random-element-selector';

const myArray = [3, 'cat', 'didgeridoo', { hello: 'World' }, 999];
console.log(randomElement(myArray)); // 'didgeridoo'
console.log(randomElement(myArray)); // 999
console.log(randomElement(myArray)); // { hello: 'World' }
console.log(randomElement(myArray)); // 999
console.log(randomElement(myArray)); // 3
console.log(randomElement(myArray)); // 3
console.log(randomElement(myArray)); // 'cat'

Note that passing-in an argument which is not an array will throw an error.

Package Sidebar

Install

npm i random-element-selector

Weekly Downloads

6

Version

1.0.2

License

MIT

Unpacked Size

2.62 kB

Total Files

4

Last publish

Collaborators

  • jethrowilliams