Here you can find the source of peek()
/**//from w w w .j a v a2 s. com * Add peek() to the Javascript Array prototype * Returns the top of the stack or null * if the stack is empty without pop()ing it off. * http://ajax.sys-con.com/node/347048 accessed 06/02/2010 * Reprint of Real-World AJAX: Secrets of the Masters published by SYS-CON ISBN 0-9777622-0-3 */ Array.prototype.peek = function(){ if (this.length > 0){ return this[this.length - 1]; } else { return null; } }
Array.prototype.peek = function () { return this[this.length - 1]; };
Array.prototype.peek = function() { var index = Math.floor(Math.random() * this.length); return this[index]; };
Array.prototype.peek = function(index) { if(!index) index = 0; return this[this.length - index - 1];
Array.prototype._peek = function(){ if(this.length > 0) return this[this.length - 1]; return null; };