-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayjs.html
More file actions
160 lines (135 loc) · 3.53 KB
/
arrayjs.html
File metadata and controls
160 lines (135 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html>
<head>
<title>Array Js</title>
</head>
<body>
<p>Hi hello</p>
</body>
<script type="text/javascript">
//manual array
let j= new Array("aung aung","maung maung","kyaw kyaw");
console.log(j);
let k=Array("su su","nu nu","mya mya");
console.log(k);
let l=[1200,1300,"aung",1700];
console.log(l);
console.log(l[3]);
//String is Character Array in Js
let aung= "aung ko ko";
console.log(aung[5]);
//outside array
//let m= new Array();
let m=[]
m[0]= "red";
m[1]="green";
m[2]="black";
m[3]="orange";
m[4]="blue";
console.log(m);
// Default Function for array
// console.log("array to string=" +m.toString());
// console.log("array to string by special char=" + m.join("/"));
// console.log("array value count="+ m.length);
// //Adding array data by behind
// m.push("gold");
// m.push("gray");
// console.log(m);
// //delete array by behind
// m.pop();
// console.log(m);
// m.pop();
// console.log(m);
// document.write(m);
//remove from start, beware index number
// m.shift();
// console.log(m);
//add data at front
// m.unshift("yellow");
// console.log(m);
//delete is not remove index number,
//delete m[2];
//console.log(m);
// m[2]="pink";
// console.log(m);
// Add data, by start from index number
// m.splice(2,0,"apple","mango","grape");
// console.log(m);
//Remove data where to how many
// m.splice(1,3);
// console.log(m);
// Array Combine
let arr1= ["aung aung","maung maung","zaw zaw","ko ko","kyaw kyaw","kaung kaung"];
let arr2=["nu nu","mya mya","su su","hla hla"];
let arr3=[1500,528];
// let cbm=arr1.concat(arr2);
// console.log(cbm);
//get data from exists array, 2 in slice parameter is index number
// let arr4 = arr1.slice(2);
// console.log("arr4="+arr4);
// let arr5 = arr1.slice(0,2);
// console.log(arr5);
console.log(arr1);
//Sort A to Z
console.log(arr1.sort());
console.log(arr1.reverse());
let arr4=[10,23,14,11,50,4,6,7,120,45,300,66];
console.log(arr4);
console.log(arr4.sort(function(a,b){
return a-b;
}))
console.log(arr4.sort(function(a,b){
return b-a;
}))
//Array as Object
//Manual Array (index+value)
//Associate Array (index+key+Value)
let arr5=[];
arr5["firstname"]="Ko";
arr5["lastname"]="Aung";
arr5["age"]=26;
arr5["address"]="Mandalay";
console.log(arr5);
console.log(arr5["address"]);
//Array as Object(API)
let arr6={
firstname :"Tin",
middlenae :"Htut",
lastname :"Aung",
age :27
}
console.log(arr6);
let arr7={
"firstname" :"Tin",
"middlenae" :"Htut",
"lastname" :"Aung",
"age" :27
}
console.log(arr7);
//Comparison Operators
// == equal to
// ===equal value and equal type
// !=not equal
// !==not equal value and not equal type
// > greater than
// < less than
// >=greater than or equal to
// <= less than or equal to
// ? tinary Operators
let num1=4;
let num2=2;
document.write("equal to result="+(num1==num2)+"<br>");
document.write("equal value and equal type result="+(num1===num2)+"<br>");
document.write("not equal to result="+(num1!=num2)+"<br>");
document.write("not equal value and not equal type result="+(num1!==num2)+"<br>");
document.write("greater than result="+(num1>num2)+"<br>");
document.write("less than result="+(num1<num2)+"<br>");
document.write("greater than or equal to result="+(num1>=num2)+"<br>");
document.write("less than or equal to result="+(num1>=num2)+"<br>");
document.write("tinary result="+(num1>num2?"Yes,num1 is greater than num2":"No,num1 is not greater than num2")+"<br>");
// Logical Operator 3
//&& and
//|| or
// ! not
</script>
</html>