Mega Code Archive

 
Categories / JavaScript Tutorial / Object Oriented
 

Add method to Array object

Array.prototype.enqueue =  function(vItem) {     this.push(vItem); }; Array.prototype.dequeue = function() {     return this.shift(); }; Array.prototype.indexOf = function (vItem) {     for (var i=0; i < this.length; i++) {         if (vItem == this[i]) {             return i;         }     }     return -1; } var aColors = new Array("red", "green", "yellow"); alert(aColors.indexOf("green"));