JavaScript Array Prototype Property

You are Here:

JavaScript Array Prototype Property

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

Note: Prototype is a global object constructor which is available for all JavaScript objects.

In the following example, we will create a new method toAlternateCase() to alternate the case of the elements in an array.


HTML Online Editor
<!DOCTYPE html> <html> <body> <script> Array.prototype.toAlternateCase = function() { for(i=0; i<this.length; i++){ // Get one Element, say, "Aston Martin" var oneElement = this[i]; var temp = ""; // Convertion takes place here for(j=0; j<oneElement.length; j++){ if(j % 2 == 0) temp += oneElement[j].replace(oneElement[j], oneElement[j].toUpperCase()); else temp += oneElement[j].replace(oneElement[j], oneElement[j].toLowerCase()); } // Replace Actual string with Converted string this[i]= temp; } }; var myCar = ["Aston Martin", "Jaguar", "Maserati"]; myCar.toAlternateCase(); document.write(myCar[0]); </script> </body> </html>


Array.prototype.anyName = function() { // code }


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author