Skip to content

Commit 8682266

Browse files
committed
forofinloop
1 parent 955af4c commit 8682266

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Loops/forinof.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
// for..in loop
3+
// The for..in loop is used to iterate over the properties of an object.
4+
const person = {
5+
name: "John",
6+
age: 30,
7+
city: "New York"
8+
};
9+
10+
for (let i in person) {
11+
console.log(person[i]);
12+
}
13+
14+
15+
// for..of loop
16+
// The for..of loop is used to iterate over iterable objects like arrays, strings, etc.
17+
var numbers = [1, 2, 3];
18+
var sum = 0;
19+
for (let i of numbers) {
20+
//console.log();
21+
sum += i;
22+
23+
}
24+
console.log("Sum is " + sum);

0 commit comments

Comments
 (0)