Array prototype Constructor - Javascript Array

Javascript examples for Array:prototype Constructor

Description

The prototype constructor can add new properties and methods to the Array() object.

Array.prototype refers to the Array() object itself.

Syntax

The following code shows how to Make a new array method that transforms array values into upper case:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
Array.prototype.myUcase = function() {
    var i;
    for (i = 0; i < this.length; i++) {
        this[i] = this[i].toUpperCase();
    }/*from  w w w  .j ava  2  s .  com*/
};

function myFunction() {
    var fruits = ["a","b","c","d","e"];
    fruits.myUcase();
    document.getElementById("demo").innerHTML = fruits;
}
</script>

</body>
</html>

Related Tutorials