Javascript examples for Array:prototype Constructor
The prototype constructor can add new properties and methods to the Array() object.
Array.prototype refers to the Array() object itself.
The following code shows how to Make a new array method that transforms array values into upper case:
<!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>