arrayJS is born out of my addiction to ruby and the simple usage of arrays in that language. I really like the way of collecting and filtering in one method chained line, instead of writing multiple foreach-blocks. I tried to keep it simple and lightweight and use native array-methods whenever it was applicable. Sometimes it was neccessary to reimplement features in regard of consistency.


No more talking. Just open up the console of your Browser and try some of the examples beneath:

var myArray = _([10, 2, 4, 8]);  

myArray.filter(function() { return this > 3; })  
       .collect(function() { return this*2;})  
       .each(function(i) { console.log(this, i); });  

> 20 0
> 8 1
> 16 2
> [20, 8, 16]

But it can also be used without the array-literals. Every argument is then interpreted as an element of the array. Because of this, it’s not possible to specify further arguments in the constructor methods. Every argument will be treated as an array-element.

_(10, 2, 4, 8);  

> [10, 2, 4, 8]

Sometimes it is easier to separate items of an array with whitespaces in a string, so this is also possible:

_("foo bar yeah this works!");  

["foo", "bar", "yeah", "this", "works!"]

Supported Methods

All methods can be found in the Collection-Docs