Array.prototype.each = function(fn) { return this.length ? [fn(this.slice(0,1))].concat(this.slice(1).each(fn)) : []; }; [1,2,3,4].each(function(x){ document.write(x + "<br/>"); });