0% found this document useful (0 votes)
22 views2 pages

Javascript

The document provides examples of different types of loops in JavaScript, including while loops, for...in loops, and for...of loops. It demonstrates how to iterate over objects and arrays, printing keys and values. The outputs of each loop are shown, illustrating how they function with sample data.

Uploaded by

sajal agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Javascript

The document provides examples of different types of loops in JavaScript, including while loops, for...in loops, and for...of loops. It demonstrates how to iterate over objects and arrays, printing keys and values. The outputs of each loop are shown, illustrating how they function with sample data.

Uploaded by

sajal agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

JAVASCRIPT:-

LOOPS:-
//while loop//

let i=0;
while(i<10){
console.log("hello world")
i++
}
output:-it will print hello world 10 times
//for...in//
let animal={
name:"zebra",
leg:4
};
for(let key in animal){
console.log(key);
}

output:-name
leg
=>
let animal={
name:"zebra",
leg:4
};
for(let key in animal){
console.log(key,animal[key]);
}
outpuut:-name zebra
leg 4

//arrays//
let names=["rahul","neha","aman","rishab"];

for(let index in names){


console.log(index)
}

output:-
0
1
2
3

=>
let names=["rahul","neha","aman","rishab"];

for(let index in names){


console.log(index,names[index])
}
output:-
0 rahul
1 neha
2 aman
3 rishab

//for..of//
for(let name of names){
console.log(name)
}
output:-
rahul
neha
aman
rishab

You might also like