Array.prototype (Property)

The prototype for the Array object which can be used to extend the interface for all Array objects.

Availability:

ECMAScript edition - 2
JavaScript - 1.1
JScript - 3.0
Internet Explorer - 4.0
Netscape - 3.0
Property/method value type:Array object
JavaScript syntax:-Array.prototype
-myArray.constructor.prototype

The prototype for an array is the original Array prototype object.

Array objects inherit many methods and properties from their prototype parent. Enquiring the prototype of a an object whose provenance is unknown will tell you what sort of object that is.

Array objects inherit these properties from the built-in Array prototype:

Array objects inherit these methods from the built in Array prototype:

Array instances provide these properties themselves even if the prototype has them:

The example demonstrates how to provide extensions to all instances of this class by adding a function to the prototype object.

Example code:

   <HTML>
   <HEAD>
   </HEAD>
   <BODY>
   <SCRIPT>
   // Define a function that duplicates the item at the end of
   // the array
   function dupe()
   {
      if(this.length != 0)
      {
         myTail = this[this.length-1];
         this[this.length] = myTail;
         return myTail;
      }
   }
   
   // Register the new function
   Array.prototype.dupe = dupe;
   
   // Create an array and test the Array.dupe() method
   myArray = new Array("AAA", "BBB", "CCC");
   document.write("Array<BR>")
   displayArrayAsTable(myArray);
   document.write("Array.dupe()<BR>")
   document.write(myArray.dupe())
   document.write("<BR>")
   document.write("<BR>")
   document.write("Array after dupe() call<BR>")
   displayArrayAsTable(myArray);
   
   // Display an array in a table
   function displayArrayAsTable(anArray)
   {
      myLength = anArray.length;
      document.write("<TABLE BORDER=1>");
      for(myIndex = 0; myIndex < myLength; myIndex++)
      {
         document.write("<TR><TD>");
         document.write(myIndex);
         document.write("</TD><TD>");
         document.write(anArray[myIndex]);
         document.write("</TD></TR>");
         document.write("</TD></TR>");
      }
      document.write("</TABLE><BR><BR>")
   }
   </SCRIPT>
   </BODY>
   </HTML>

See also:Array object, Array(), Array(), Array.concat(), Array.constructor, Array.join(), Array.length, Array.pop(), Array.push(), Array.reverse(), Array.shift(), Array.slice(), Array.sort(), Array.splice(), Array.toSource(), Array.toString(), Array.unshift(), prototype property

Property attributes:

ReadOnly, DontDelete, DontEnum.

Cross-references:

ECMA 262 edition 2 - section - 15.4.3.1

ECMA 262 edition 3 - section - 15.4.3.1