The most viewed items
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;
}
No comment to show.