es-toolkit/docs/reference/compat/util/toArray.md
HyunWoo Choi 8caab968b2
feat(toArray) : Add toArray to compat layer (#853)
* feat : add toArray

* feat : toArray bench

* docs : add toArray

* Update src/compat/util/toArray.ts

---------

Co-authored-by: Sojin Park <raon0211@gmail.com>
2024-11-29 16:44:35 +09:00

740 B
Raw Permalink Blame History

toArray

::: info This function is only available in es-toolkit/compat for compatibility reasons. It either has alternative native JavaScript APIs or isnt fully optimized yet.

When imported from es-toolkit/compat, it behaves exactly like lodash and provides the same functionalities, as detailed here. :::

Converts value into an array.

Signature

function toArray(value?: unknown): any[];

Parameters

  • value (unknown): The value to convert.

Returns

(any[]): Returns the converted array.

Examples

toArray({ a: 1, b: 2 }); // returns [1, 2]
toArray('abc'); // returns ['a', 'b', 'c']
toArray(1); // returns []
toArray(null); // returns []