oneof
v2.2.0
Published
Select a random item from an array
Maintainers
Readme
oneof
Select a random item from an array.
Installation
npm install oneofUsage
import oneof from 'oneof';
oneof(['apple', 'banana', 'cherry']); // => 'banana' (random)
oneof([1, 2, 3, 4, 5]); // => 3 (random)
oneof(['only']); // => 'only'
oneof([]); // => null
oneof(); // => nullAPI
oneof(array)
Returns a random item from the array, or null if the array is empty or undefined.
| Parameter | Type | Description |
|-----------|---------|--------------------------|
| array | Array | The array to select from |
Returns: A random item from the array, or null.
License
ISC
