Javascript - Array prototype Property

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

Description

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

When adding a property, all array objects will be given the property, and its value, as default.

When adding a method, all array objects will have this method.

Array.prototype refers to the Array class itself.

Syntax

Array.prototype.name = value

Example

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

Demo

Array.prototype.myUcase = function() {
    var i;//from  w  w  w.ja  v  a2s.com
    for (i = 0; i < this.length; i++) {
        this[i] = this[i].toUpperCase();
    }
};

var myArray = ["XML", "Json", "Database", "Mango"];
myArray.myUcase();
console.log( myArray );

Result