-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforEach.js
More file actions
51 lines (48 loc) · 873 Bytes
/
Copy pathforEach.js
File metadata and controls
51 lines (48 loc) · 873 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
47
48
49
50
51
const pets = [
{
name: "snoop",
type: "dog",
age: 9,
weight: 15.0
},
{
name: "miau",
type: "cat",
age: 5,
weight: 3.0
},
{
name: "gulp",
type: "fish",
age: 1,
weight: 0.01
},
{
name: "pé de pano",
type: "horse",
age: 22,
weight: 200.0
},
{
name: "mayko",
type: "donkey",
age: 7,
weight: 15.0
},
{
name: "bolt",
type: "turtle",
age: 112,
weight: 5.5
}
];
// const forEachPetNames = pets.forEach((pet) => {
// return pet.name
// }); //undefined
// realizando a mesma operação que o map
const forEachPetNames = []
pets.forEach((pet) => {
forEachPetNames.push(pet.name);
});
console.log(forEachPetNames);
console.log(pets);