node package manager


Extension of native Array object to make it a collection model


Extension of native Array object to make it a collection model. But it still real Array. So you can you can just wrap any exist Array in your project.

via npm

npm install array-model

Just create a array, call method .model() and you will have great collection object.

Simple example prevents addition of objects with wrong type.

var arr = [].model();
arr.on('add', function(val, pos, arr) {
    if (typeof val !== 'number')
        arr.splice(pos, 1);
console.log(arr); // [42] 
console.log(arr); // [42] 
console.log(arr); // [42, 24] 

Events work great even with assignments.

var arr = [1,2,3].model()
arr.on('add', function(val, pos) {
    console.log(val, pos);
arr.on('remove', function(val, pos) {
    console.log(val, pos);
arr[1] = 4
// 2, 1 
// 4, 1 

Array-Model provides useful getters for you!

var arr = [1,2,3].model();
arr.get(function(val) {
    return val*val;
console.log(array.slice()); // [1,4,9] 
console.log(array[2]); // 9 

See more examples in

Assignment to not exist values. It will not work and probably break your object.

var arr = [].model();
arr.on('add', function(val, pos) { // won't be fired 
    console.log(val, pos);
arr[0] = 'data';