JavaScript Array Properties

In this JavaScript Array Properties we will learn about Javascript constructor , javascript length and javascript prototype.

JavaScript constructor

JavaScript Array Properties — In JavaScript, the constructor property returns the constructor function for an object. For JavaScript arrays the constructor property returns function Array() { [native code] }

var fruits = ['Banana', 'Orange' ,'Apple']; fruits.constructor ; //Returns // function Array() { [native code] }

JavaScript length

The length property sets or returns the number of elements in an array.

var fruits = ['Banana', 'Orange' ,'Apple']; fruits.length ; //Returns 3 var vegetables = []; vegetables.length = 3; // function Array length to 3

JavaScript prototype

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

//Make a new array method Array.prototype.myUcase = function(){ for (i=0; i < this.length;i++){ this[i] = this[i].toUpperCase(); } } // Make an array, then call the myUcase method: var fruits = ['Banana', 'Orange' ,'Apple']; fruits.myUcase();

I hope you like this amazing article.

Also Read :