node package manager

Introducing npm Enterprise add-ons. Integrate third-party dev tools into npm…


Sorted Array - uses binary search for fast insertion / reading

sarray - Sorted array in javascript


  • Uses binary-sort to insert and search in array.

Much faster than searching through a normal array, as per this (maybe unfair) benchmark:

var SortedArray = require('sarray');
var arr = SortedArray([5,4,2,1]);
// arr will now contain 1, 2, 3, 4, 5 
var arr = SortedArray(function(a, b) {
    return a.val - b.val;
arr.add({val: 5}, {val: 3});
// arr now contains [{val: 3}, {val: 5}]; 

This class is actually a subclass of sorted set, except that it doesn't maintain uniqueness in the array, so take a look at for further info.

npm install sarray