For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/conversion/toArray.md.

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

T[]