Home > Javascript > A JavaScript Collection Implementation

A JavaScript Collection Implementation

To see all the APIs, just grab the source code and tests available at :

Basic Usage:

Usage

// Create some data
var obj1 = {name:'Ana', age:19, camera:'AE1'};
var obj2 = {name:'Rod', age:76, camera: 'Rolleiflex'};
var obj3 = {name:'Sandy', age:69, camera: 'EOS'};

// Create a collection instance
var col = new Collection();

// Add data to collection object
col.add(obj1);
col.add(obj2);
col.add(obj3);

// Sort by property
col.sortBy('name');

// Call a function on each collection item 
col.each( 
  function(it){
    alert('Camera is '+ it.camera+ ', age=' +it.age);
  });

alert(col.flatten(' : ', 'camera'));

// Remove an item based on a property value
col.removeByPredicate(
 function(it){ return it['name']=='Rod';}
);

Categories: Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.