HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript Array prototype Constructor

Array Object Reference JavaScript Array Object

Example

Make a new array method that transforms array values into upper case:

Array.prototype.myUcase=function()
{
  for (i=0;i<this.length;i++)
    {
    this[i]=this[i].toUpperCase();
    }
}

Make an array, then call the myUcase method:

var fruits=["Banana","Orange","Apple","Mango"];
fruits.myUcase();

The values in the fruits array is now:

BANANA,ORANGE,APPLE,MANGO

Try it yourself »

Definition and Usage

The prototype constructor allows you to add new properties and methods to the Array() object.

When constructing a property, ALL arrays will be given the property, and it's value, as default.

When constructing a method, ALL arrays will have this method available.

Note: Array.prototype does not refer to a single array, but to the Array() object itself.

Note: Prototype is a global object constructor which is available for all JavaScript objects.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The prototype property is supported in all major browsers.


Syntax

Array.prototype.name=value


Array Object Reference JavaScript Array Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE