
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
Keep an array of objects indexed by field, for super-fast retrieval.
Have you ever created an array, filled it with objects, and then wanted to sometimes
retrieve the objects based on "id", but sometimes based on "slug"? Did you simple
create a find(key, value) method? That's okay, I've done it too. Just keep reading
though, you'll love this module.
Reol lets you create an array of objects pretty much like you've always done, but you can also specify fields to be indexed. The advantage of indexes is that retrieving an object based on the value of an indexed field is a lot faster.
In short, this module is ideal when you have a lot of objects which you want to find based on some keys, where the indexed values do not change and elements do not need to be removed.
As you can see, Reol's strength is when you're reading more than writing.
Run make benchmark to test yourself on your own machine or check out
this jsperf test for fancy graphs.
npm install reol -Svar Reol = require('reol'); // To use in scriptsbower install reolJust copy dist/reol.min.js and put it where you like it. Reol should work in
all js environments, including commonJS (node) and AMD (requireJS) as well as
old-fashioned <script src="dist/reol.min.js"></script>-style.
Create an instance
// Array
var array = [];
// Reol
var list = new Reol({
test: true,
'parent.child': true // Supports deep indexing
});
Create and add a bunch of elements at the same time
// Array
var array = [obj1, obj2, obj3];
// Reol
var list = new Reol({
test: true,
'parent.child': true // Supports deep indexing
}).merge(array);
Add an element
// Array
array.push(obj);
// Reol
list.add({
test: 'meow',
parent: {
child: 'baahh'
}
}).add(obj4); // Chain adds if you feel like, just 'cause you can
Indexing works even with undefined and complex values, though the latter is not recommended. If you want to index objects, implement a custom .toString method, or they will all be treated as the same value.
list.add({
test: function(){
console.log("seriously, avoid doing this");
},
parent: {
child: {
and: 'this'
}
}
});
// Un-indexed fields also work
list.add({
woot: 'mooo'
});
// Find all matches
list.find({ test: 'meow' });
// findOne will speed up best-case scenarios for queries on un-indexed fields
list.findOne({ woot: 'mooo' });
Searching on multiple fields is not allowed. Use filtering instead.
// By matching an object
list.find({ test: 'meow' }).filter({ 'nested.child': 'baah' });
// By supplying your own comparison function, [].filter() style
list.find({ test: 'meow' }).filter(function (element) {
return !!(element.nested && element.nested.child === 'baah');
});
You can copy lists using clone
var newList = list.clone();
var evenNewer = newList.find({ test: 'test' }).clone();
Removing elements working since 0.3.
// First find or filter out the unwanted elements, the .remove() them
list.find({ test: 'meow' }).remove();
// Or supply a collection of elements
list.remove(list.find({ test: 'meow' }));
// Note that this removes the element(s) from the parent element (eg "list")
// Create a new instance with .clone() to remove elements from only that set
list.find({ test: 'meow' }).clone().filter({ more: 'conditions' }).remove();
You can also use the following regular array-methods:
These are reimplemented as close to the native ones as possible. Accessor methods returns the element (or an instance of Reol.List in case of multiple elements) while mutator methods returns itself so it can be chained (unless it's supposed to return a result of course). All other methods are left with the native implementation and should work but are not tested.
Ordered somewhat by simpleness and likelihood of being implemented.
I just threw this together in a few hours to solve my problem at hand. If you want to pick something on the todo list or have an opinion on how some method should be implemented (or maybe not implemented at all), please don't hestitate to create an issue, submit a pull request, tweet/email me or whatever.
For example I'm at the moment not sure if I should keep Reol as a very small and basic utility or extend it with rather complex (but some might argue essential) functionality such as .remove() and advanced indexing.
When contributing, please take care to maintain the current coding style and add tests for any added/changed functionality, and issue the pull-request to the develop branch from your own feature-branch. Also avoid unnecessary merges, it's just ugly.
Run make test to test.
MIT
FAQs
Keep an array of objects indexed by field, for super-fast retrieval.
We found that reol demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.