English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.).
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();
All browsers fully support the prototype property:
Property | |||||
Prototype | Yes | Yes | Yes | Yes | Yes |
The following example uses the prototype property to add properties to the fruits object:
Array.prototype.creator = 'ME';Test and See‹/›