Skip to content

Commit 11a635e

Browse files
committed
for...in and for...of Loop
1 parent ba6334c commit 11a635e

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
8+
// for...in Loop
9+
10+
<script>
11+
12+
// example 1 -
13+
14+
const person = {
15+
name: "Nishant",
16+
age: 25,
17+
city: "Delhi"
18+
}
19+
20+
console.log(person.name); // Nishant
21+
22+
for(i in person){
23+
console.log(i,' = ',person[i]);
24+
}
25+
26+
27+
</script>
28+
29+
30+
31+
</head>
32+
<body>
33+
34+
35+
36+
37+
</body>
38+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
8+
// for...of Loop
9+
10+
<script>
11+
12+
// example 1 -
13+
14+
const arr = [10,20,30,40,50];
15+
16+
for(i of arr){
17+
console.log(i);
18+
}
19+
20+
for(i in arr){
21+
console.log(arr[i]);
22+
}
23+
</script>
24+
</head>
25+
<body>
26+
27+
</body>
28+
</html>

0 commit comments

Comments
 (0)