-
Notifications
You must be signed in to change notification settings - Fork 0
/
forin.js
64 lines (64 loc) · 1.38 KB
/
forin.js
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
54
55
56
57
58
59
60
61
62
63
64
function forInSample()
{
let product = {
productId : 680,
name: "HL Road Frame=Black, 58",
productNumber : "FR=R92B-58",
color: "Black",
standardCost:1059.31,
listPrice:1431.50,
calculateGrossProfit: function()
{
return this.listPrice - this.standardCost;
}
};
for(const key in product)
{
console.log("'" + key+ "'=" +product[key]);
}
}
forInSample();
function forOfSample()
{
let products = [{
productId : 680,
name: "HL Road Frame=Black, 58",
productNumber : "FR=R92B-58",
color: "Black",
standardCost:1059.31,
listPrice:1431.50
},
{
productId : 707,
name: "Sport-100 Helmet, Red",
productNumber : "HL-U509-R",
color: "Red",
standardCost:13.08,
listPrice:34.99
},
{
productId : 709,
name: "Mountain Bike Socks, M",
productNumber : "S0-B909-M",
color: "White",
standardCost:3.3963,
listPrice:9.50,
}
];
for(const items of products)
{
console.log(JSON.stringify(items));
}
}
forOfSample();
function loopStringSample()
{
let productName = "HL Road Frame - Black,58";
let letters = "";
for(const char of productName)
{
letters += char;
}
console.log(letters);
}
loopStringSample();