THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript Array prototype Constructor

JavaScript Array Reference JavaScript Array Reference

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

Property
prototype Yes Yes Yes Yes Yes

Syntax

Array.prototype.name=value

JavaScript Array Reference JavaScript Array Reference