JavaScript Array Properties

JavaScript Array Properties

Table of Contents

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] }

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

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 article.

Also Read :