to-array
Try convert an object into an Array
Installation
$ component install timoxley/to-array
Examples
// Array-likesvar divs = document // `NodeList` of `HTMLDivElement` // => Array of `HTMLDivElement` { // => [1, 2]}1 2 // Primitives // => ['hello'] // => [12345] // => [/regex/] // => [null] // => [{}] // => [window] // => [Wed Nov 07 2012 04:40:26 GMT+1000 (EST)] // Special case // => []
API
toArray(collection): Array
Array-like structures like arguments
, NodeList
or HTMLCollection
, will be converted into Array
s.
Date
, String
, Regex
, null
, Object
, and Function
will
convert into an Array
, with a single element being whatever was
passed to toArray
.
undefined
will return an empty Array
Alternatives
wilmoore/to-array.js: slightly different semantics.
Contributors
- 21 Tim Oxley 75.0%
- 4 Jonny Strömberg 14.3%
- 2 Forbes Lindesay 7.1%
- 1 Dominic Barnes 3.6%
License
MIT