-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.forEach.js
More file actions
46 lines (39 loc) · 831 Bytes
/
Copy patharray.forEach.js
File metadata and controls
46 lines (39 loc) · 831 Bytes
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
// The forEach() method executes a provided function once for each array element.
const products = [
{ item: 'item 1', price: 10 },
{ item: 'item 2', price: 20 },
{ item: 'item 3', price: 30 },
{ item: 'item 4', price: 40 },
{ item: 'item 5', price: 50 },
{ item: 'item 6', price: 60 }
];
products.forEach(item => {
console.log(item.price);
});
// output
// 10
// 20
// 30
// 40
// 50
// 60
// No operation for uninitialized values (sparse arrays)
const products2 = [
{ item: 'item 1', price: 10 },
{ item: 'item 2', price: 20 },
{ item: 'item 3', price: 30 },
,
{ item: 'item 4', price: 40 },
{ item: 'item 5', price: 50 },
{ item: 'item 6', price: 60 }
];
arproducts2r1.forEach(item => {
console.log(item.price);
});
// output
// 10
// 20
// 30
// 40
// 50
// 60