JavaScript Array prototype property

Definition and usage

prototype It is a global constructor function available for all JavaScript objects.

prototype Reference the global Array() object.

prototype The constructor allows you to add new properties and methods to the array.

When a new property is constructed, all arrays will obtain this property and its value.

When a new method is constructed, all arrays will obtain this method.

Instance

Create a new array method to convert array values to uppercase:

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

Create an array and then call the myUcase method:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.myUcase();

Try it yourself

Syntax

Array.prototype.name = value

Browser support

All browsers fully support prototype:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support

Related Pages

Tutorial:JavaScript Array

Tutorial:JavaScript Array Const

Tutorial:JavaScript Array Methods

Tutorial:JavaScript Sort Array

Tutorial:JavaScript Array Iteration