R
fn

toArray

v0.0.10tested

Normalize an `Arrayable<T>` value into an array. `undefined` and `null` become an empty array; a single value is wrapped; arrays are returned as-is (no copy).

Examples

ts
toArray(1) // => [1]
ts
toArray([1, 2]) // => [1, 2]
ts
toArray(undefined) // => []

Signature

ts
export function toArray<Value>(value: Arrayable<Value> | null | undefined): Value[]{ ... }

Type Parameters

Value

Parameters

ParameterTypeDescription
valueArrayable<Value> | null | undefinedThe value to normalize

Returns

Value[]The value as an array