Converts primitives and objects (plain or array-like) to a sensible array representation for Node.js and the browser.
toArray([1, 2, 3]);
//=> [1, 2, 3]
toArray(void 0 || null)
//=> []
toArray('id');
//=> ['id']
toArray('a,b,c', ',');
//=> ['a', 'b', 'c']
toArray(42);
//=> [42]
var elements = document.getElementsByTagName('textarea');
toArray(elements);
//=> [ <textarea id="wgjc"></textarea>, <textarea id="wgjs"></textarea>, <textarea id="wgju"></textarea> ]
<div id="example" class="one two">
toArray(document.getElementById('example').classList);
//=> [ "one", "two" ]
% npm install to-array.js
% component install wilmoore/to-array.js
% bower install to-array.js
% jam install to-array.js
% volo add wilmoore/to-array.js
-
download
% curl -#O https://raw.github.com/wilmoore/to-array.js/master/to-array.js
-
use
<script src="to-array.js"></script>
- timoxley/to-array: slightly different semantics.
- _.toArray: I didn't want this:
_.toArray('hi') // ['h', 'i']
% make to-array.js
% git commit …
% npm version minor
% git push
% git push --tags
% npm publish