> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# toArray

Converts a value to an array.

- Arrays are returned as-is.
- Iterables (strings, Sets, Maps) are spread into an array.
- `null` / `undefined` return `[]`.
- All other values are wrapped in a single-element array.

```typescript
toArray(new Set([1, 2])) // [1, 2]
toArray('abc') // ['a', 'b', 'c']
toArray(null) // []
toArray(42) // [42]
```

## Usage

### `toArray<T>(value: Iterable<T> | T | null | undefined)`

Converts a value to an array.

- Arrays are returned as-is.
- Iterables (strings, Sets, Maps) are spread into an array.
- `null` / `undefined` return `[]`.
- All other values are wrapped in a single-element array.

```typescript
import { toArray } from 'massaman'
// or:  import { toArray } from 'massaman/conversion'

toArray(new Set([1, 2])) // [1, 2]
toArray('abc') // ['a', 'b', 'c']
toArray(null) // []
toArray(42) // [42]
```

#### Parameters


valueIterable<T> | T | null | undefinedrequired

the value to convert.

#### Returns

an array containing the input values, or an empty array for `null` and `undefined`.

```typescript
T[]
```
