1// The for in statement loops through the properties of an Object
2for (key in object) {
3 // code block to be executed
4}
5
6const customer = {name:"Jack", lastname:"Nolan", age:45};
7
8let text = "";
9for (let key in customer) {
10 text += customer[key];
11}
Output: Jack Nolan 45
1const numbers = [3, 6, 12, 24, 48, 63];
2
3let text = "";
4for (let x in numbers) {
5 text += numbers[x];
6}
For in Loop Usage in HTML
1<!DOCTYPE html>
2<html>
3<body>
4<h2>JavaScript For in loop</h2>
5<p id="demo"></p>
6
7<script>
8 const numbers = [3, 6, 12, 24, 48, 63];
9
10 let text = "";
11 for (let x in numbers) {
12 text += numbers[x] + "<br/>";
13 }
14 document.getElementById("demo").innerHTML = text;
15</script>
16
17</body>
18</html>