Array.prototype.insertInOrder = function(item) { for (var i = 0; this[i] < item && i < this.length; i++); this.splice(i, 0, item); };