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 www  .j  a  v a  2 s .co  m*/
    for (i = 0; i < this.length; i++) {
        this[i] = this[i].toUpperCase();
    }
};

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

Result