forked from TelerikAcademy/JavaScript-Fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path7. for-in-loop.html
53 lines (49 loc) · 1.27 KB
/
7. for-in-loop.html
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Loops - for-in loops</title>
<link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
<div id="js-console">
</div>
<script src="scripts/js-console.js">
</script>
<script>
function printAll(obj) {
jsConsole.writeLine('--------------------------');
for (var property in obj) {
jsConsole.writeLine('obj[' + property + '] = ' + obj[property]);
}
jsConsole.writeLine('--------------------------');
}
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
printAll(arr);
var doc = document;
printAll(doc);
var obj = {
firstName: 'Doncho',
lastName: 'Minkov',
age: 23,
fullName: function () {
return this.firstName + " " + this.lastName
},
toString: function () {
return 'Name: ' + this.fullName() + '\nAge: ' + this.age
}
};
function printObject(obj) {
jsConsole.writeLine('--------------------------');
for (var property in obj) {
if (typeof(obj[property]) != 'function') {
jsConsole.writeLine('obj[' + property + '] = ' + obj[property]);
} else{
jsConsole.writeLine('obj[' + property + '] = ' + obj[property]());
}
}
jsConsole.writeLine('--------------------------');
}
printObject(obj);
</script>
</body>
</html>