JavaScript Array prototype
Example
Create a method that transforms array values into upper case:
Array.prototype.myUcase = function() {
for (let i = 0; i < this.length; i++) {
this[i] = this[i].toUpperCase();
}
};
Use the method on any array:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.myUcase();
Try it Yourself »
Definition and Usage
The prototype is a global constructor available for all JavaScript objects.
prototype referes to the global Array() object.
The prototype constructor allows you to add new properties and methods to Arrays.
When constructing a new property, ALL arrays will get this property and its value.
When constructing a new method, ALL arrays will get this method.
Browser Support
prototype is fully supported in all browsers:
| Chrome | IE | Edge | Firefox | Safari | Opera |
| Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
Array.prototype.name = value

