-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
61 lines (40 loc) · 1.11 KB
/
test.js
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
//************1**************** */
//a)
const a={
add : [
{name:"ali",age:200},
{name:"shah",age:2031},
{name:"arslan",age:2038},
{name:"ajmi",age:2033},
{name:"shah",age:2034}
]
};
// a)Identify the piece of code is it array or object
let t=typeof a;
// b)print out the name names which is named as shah
for (let i = 0; i < a.add.length; i++) {
let text="";
if (a.add[i].name=="shah") {
//console.log(a.add[i].name);
text += a.add[i].name+" ";
// text +=a.add[i].age;
console.log(text);
}
}
// c)calculate the maximum number of age in this piece of code
var max=a.add[0].age;
for (let i = 0; i < a.add.length; i++) {
var text;
if (a.add[i].age>max) {
max=a.add[i].age;
}
}
console.log(max);
// e)write a object and push this object into this piece of code
let p={name:"Humyu",age:20};
a.add.push(p);
console.log(a.add);
// f)write a piece of code and changes the age where index is 3
let c={name:"shan",age:99};
a.add.splice(2,0,c);
console.log(a.add);