const tnwNames = ["Hla Hla", "Mya Mya", "Soe Soe", "Moe Moe"];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNames.join("
");
}
function tnwFun2(){
document.getElementById("demo").innerHTML = tnwNames.includes("Mya Mya");
}
const myLetter = "ABCDEFGHIJKL";
function tnwFun1(){
document.getElementById("demo").innerHTML = myLetter;
}
function tnwFun2(){
const result = Array.from(myLetter);
document.getElementById("demo").innerHTML = result;
}
const student = ["Aung Aung", "Maung", "Kyaw", "Zaw", "Soe", "Moe"];
let names = "";
function tnwFun1(){
student.forEach(tnwFun2);
}
function tnwFun2(item, index){
names += index + " : " + item + "
";
document.getElementById("demo").innerHTML = names;
}
const tnwAges = [19, 39, 28, 43, 29, 45, 53];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwAges.join("
");
}
function tnwFun2(){
document.getElementById("demo").innerHTML = tnwAges.findIndex(chkAge);
}
function chkAge(age){
return age > document.getElementById("myAge").value;
}
const tnwAges = [19, 39, 28, 43, 29, 45, 53];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwAges.join("
");
}
function tnwFun2(){
document.getElementById("demo").innerHTML = tnwAges.find(chkAge);
}
function chkAge(age){
return age > document.getElementById("myAge").value;
}
const tnwAges = [25, 18, 29, 20, 40, 32, 53, 24];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwAges.join("
");
}
function tnwFun2(){
const result = tnwAges.filter(chkAge);
document.getElementById("demo").innerHTML = result.join("
");
}
function chkAge(age){
return age > 20;
}
const tnwNames = ["Aye Aye", "Nwe Nwe", "Hla Hla", "Mya Mya", "Soe Soe", "Moe Moe"];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNames.join("
");
}
function tnwFun2(){
const result = tnwNames.fill("Aung Aung", 1, 3);
document.getElementById("demo").innerHTML = result.join("
");
}
const tnwAge = [20, 29, 48, 76, 50, 38, 39];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwAge.every(tnwFun2);
}
function tnwFun2(chkAge){
return chkAge > 19;
}
const tnwNames = ["Hla Hla", "Mya Mya", "Aye Aye", "Nwe Nwe", "Soe Soe", "Moe Moe", "Aung Aung"];
const y = tnwNames.entries();
for(x of y){
document.write(x + "
");
}
const people = ["Hla", "Mya", "Aung", "Maung", "Soe", "Noe", "Moe"];
function tnwFun1(){
document.getElementById("demo").innerHTML = people.join("
");
}
function tnwFun2(){
const result = people.copyWithin(3, 0, 3);
document.getElementById("demo").innerHTML = result.join("
");
}
const girls = ["Aye Aye", "Nwe Nwe", "Htwe Htwe"];
const boys = ["Aung Aung", "Maung Maung", "Kyaw Kyaw"];
const students = ["Hla Hla", "Mya Mya", "Aung Ba", "Aung Mya"];
const people = girls.concat(boys, students);
document.write(people.join("
"));
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;
}