Javascript Array insertAfter(elem, after)
Array.prototype.insertAfter = function(elem, after) { var tmp_array = []; while (this.length) { var next = this.pop(); if (next !== after) { tmp_array.push(next);/*from ww w. ja va2 s . c o m*/ } else { this.push(next); break; } } this.push(elem); while (tmp_array.length) { this.push(tmp_array.pop()); } };