Please login to start chat

ICT Solutions 11 Jun 2022, 09:47:07
Category : JavaScript Tutorials

JavaScript Array Properties

length
Sets or returns the number of elements in an array.

prototype
Allows you to add new properties and methods to an Array object.


//length
/*
const countries = ["USA", "UK", "Canada", "Myanmar", "Singapore"];

function showLength(){
document.getElementById("demo").innerHTML = countries.length;
}

//prototype

Array.prototype.tnwCase = function(){
for(let i = 0; i < this.length; i++){
this[i] = this[i].toLowerCase(); //lower case
}
};

const countries = ["USA", "UK", "Canada", "Myanmar", "Singapore"];
countries.tnwCase();

function tnwFun(){
document.getElementById("demo").innerHTML = countries;
}*/

//Another example of prototype property

function Person(first, middle, last){
this.firstName = first;
this.middleName = middle;
this.lastName = last;
}

const myFriend = new Person("Aung", "Kyaw", "Soe");
Person.prototype.nationality = "Myanmar";
Person.prototype.age = 35;

function tnwFun(){
document.getElementById("demo").innerHTML = myFriend.age;
}

To see video in YouTube.

Comments:

No comment to show.

Available Services
Download Android Application