English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Array prototype property

 JavaScript Array Object

PrototypeProperties allow you to add properties and methods to the Array() object.

Note:The prototype is a global property that is available for almost all objects (numbers, booleans, strings, dates, etc.).

Syntax:

Array.prototype.name = value

This example creates a new array method that converts array values to uppercase letters:

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

Then create an array and call the upper() method:

var fruits = ['Banana', 'Mango', 'Apple'];
fruits.upper();

Test and See‹/›

Browser Compatibility

All browsers fully support the prototype property:

Property
PrototypeYesYesYesYesYes

More Examples

The following example uses the prototype property to add properties to the fruits object:

Array.prototype.creator = 'ME';
Test and See‹/›

 JavaScript Array Object