array-keys
![release](http://img.shields.io/github/release/silverbucket/array-keys.svg?style=flat)
Very simple library to manage array elements using a key instead of array index position. When dealing with very large sets of data all organized in an object reference, if the object structure is changing a lot you can end up with memory leaks and slow performance. In these cases it's better to keep an array of objects instead of and object of objects. The cost of iterating through the array is cheaper than the lack of garbage collection which can occur in large, changing, object hashes.
environments
Should run in both node.js and browser environments.
basic usage example
var ak = new ArrayKeys({
identifier: 'key'
});
ak.getRecord('myInvalidKey'});
ak.addRecord({
key: 'myKey1',
value: 'hello world!'
});
ak.getRecord('myKey1');
ak.addRecord({
key: 'myKey2',
value: 'hello space!'
});
ak.forEachRecord(function (record) {
}).finally(function (count) {
});
ak.getIdentifiers();
events
ArrayKeys
also optionally supports emitting events. This functionality must be explicity enabled during object instantiation.
supported events
example
var ak = new ArrayKeys({
emitEvents: true
});
ak.events.on('add', function (record) {
console.log(record.id);
});
ak.addRecord({
id: 'foobar',
here: [ 'is', 'some' ],
data: true
});
credits
Project developed and maintained by Nick Jennings