-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayMethods.js
More file actions
45 lines (40 loc) · 1.53 KB
/
arrayMethods.js
File metadata and controls
45 lines (40 loc) · 1.53 KB
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
const house = { sqft: 800, bdRooms: 2, bthRooms: 1 };
let houseDetails = "<h3>Information about this house</h3>";
// for ... in method on object {}
// the ${houseDetails
let loop = 0;
for (let prop in house) {
houseDetails = `${houseDetails} ${prop}:${house[prop]}</br>`;
loop++;
console.log(`loop: ${loop}`);
}
document.getElementById("root").innerHTML = houseDetails;
const previousOWners = ["Konstantinos", "Elissabet"];
let items = "<h3>Information about another house</h3>";
let myItems = "<h3>Information about house owners</h3>";
// for .. in method on array will return the index of the the items found
for (let item in previousOWners) {
items = `${items} ${item}</br>`;
loop++;
console.log(`loop: ${loop}`);
}
document.getElementById("details").innerHTML = items;
// for ... of method on array will return the items (names) found
for (let item of previousOWners) {
myItems = `${myItems} ${item}</br>`;
loop++;
console.log(`loop: ${loop}`);
}
document.getElementById("Mydetails").innerHTML = `${myItems}`;
/*
for(let i=1; i <= 100; i++) {
console.log(i);
}
*/
/* JavaScript All-in-One For Dummies John Wiley & Sons, Inc. 2023
In practice, for loops are unpopular with experienced JavaScript developers. Like
using the var keyword, for loops are an old way to do things that shouldn't be
used. There's usually a more modern and simpler syntax for doing the same thing
that for loops do. You can learn about some of these in this chapter, and learn
about other methods that are better for looping through arrays in Chapter 6.
*/