-
Notifications
You must be signed in to change notification settings - Fork 0
/
loop.js
85 lines (66 loc) · 1.56 KB
/
loop.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//for of
var city = ["Mumbai", "Chennai", "Calcutta", "Jaipur","Canada"]
for(mycity of city) {
console.log(mycity);
}
let marks = [81,95,75];
for(score of marks){
score = score + 5;
console.log(score);
}
//score = [81+5, 95+5, 75+5]
//[86,100,80]
var city = ["Mumbai",
"Chennai",
["Rose","Lotus","Lily"],
"Calcutta",
"Jaipur",
"Canada",
];
for(mycity of city){
if(Array.isArray(mycity)){
for(myflower of mycity){
console.log(myflower);
}
} else {
console.log(mycity);
}
}
//-----------------------------------------------------------------------------
//for in
//{}
var movie ={
name: "Vikram",
rating: 5,
type: "Action"
};
for(key in movie){
//console.log(key);
console.log(movie[key]);
}
const color = ["Red", "Black", "Pink"];
color.forEach(ele => console.log(ele));
var myObj = {
"cars": {
"car1":"Ford",
"Car2":"BMW",
"Car3": "Fiat"
},"cars2": {
"car1":"Ford2",
"Car2":"BMW2",
"Car3": "Fiat2"
}
}
for(x in myObj){
console.log(myObj[x].car1);
}
Object.values(myObj).forEach((i) => console.log(i.car1));
//---------------------------------------------------------------------------------
//JSON stringify
var student = {
name : "Faiza",
age : 27,
};
const myJson = JSON.stringify(student);
console.log(myJson);
//============================================================================================