How to use Array prototype in JavaScript

In this article I have described about Array prototype property used in JavaScript.
  • 1746

JavaScript Array Prototype Property

  • As mentioned earlier that for storing multiple values in a single variable we use array object .
  • The array object has a property is known as prototype Property.
  • With the help of length Property we can add new properties and methods to the array object.

Browser support

Following are the main browsers which support the prototype Property of array object

  • Internet Explorer.
  • Firefox.
  • Opera.
  • Google Chrome.
  • Safari.

Syntax

The prototype Property of array object has following syntax

array.prototype.name=value

Lets take an example

In this program we can change elements of an array to uppercase.

<!DOCTYPE html>

<html>

<body style ="background-color:green">

<p id="menu">Use of ucase method()</p>

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

<script type="text/javascript">

    Array.prototype.myUcase = function () {

        for (i = 0; i < this.length; i++) {

            this[i] = this[i].toUpperCase();

        }

    }

    function myFunction() {

        var array = ["aman", "shubham", "nitin", "arun", "vipin"];

        array.myUcase();

        var x = document.getElementById("menu");

        x.innerHTML = array;

    }

</script>

</body>

</html>

 

Output


arry upcase1.jpg


When we click on button


array upcase2.jpg

Further Readings

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.