getRandomItem()function
getRandomItem(arr: ImmutableArray<T>): T
| Param | Type | |
|---|---|---|
arr | ImmutableArray<T> | Array to pick an item from. required |
| Return | |
|---|---|
T | Single item chosen at random from arr. |
| Throws | |
|---|---|
unknown | RequiredError If the chosen item is undefined (e.g. the array is empty). |
Get a random item from an array.
Examples
const item = getRandomItem(["a", "b", "c"]); // e.g. `"b"`