# oneof

> Select a random item from an array

Latest version **2.2.0** (published 2026-01-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install oneof
pnpm add oneof
yarn add oneof
bun add oneof
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2026-01-18 |
| First published | 2017-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 |
| Dependencies | 0 |
| Unpacked size | 35.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | fantasyui.com |
| Maintainers | fantasyui.com |
| Keywords | random, array, pick, select, choice, sample |

## Links

- npm: https://www.npmjs.com/package/oneof
- Repository: https://github.com/fantasyui-com/oneof
- Homepage: https://github.com/fantasyui-com/oneof#readme
- Issues: https://github.com/fantasyui-com/oneof/issues
- npm.io page: https://npm.io/package/oneof

## Recent versions

- 2.2.0 (latest) — 2026-01-18
- 2.1.0 — 2021-11-19
- 2.0.0 — 2020-01-21
- 1.1.0 — 2019-04-26
- 1.0.1 — 2017-05-22

## README

# oneof

Select a random item from an array.

## Installation

```sh
npm install oneof
```

## Usage

```js
import oneof from 'oneof';

oneof(['apple', 'banana', 'cherry']); // => 'banana' (random)
oneof([1, 2, 3, 4, 5]);               // => 3 (random)
oneof(['only']);                      // => 'only'
oneof([]);                            // => null
oneof();                              // => null
```

## API

### 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

---
_Source: https://npm.io/package/oneof · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
