forked from DouglasHdezT/JavaScript_NodeCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample1.js
More file actions
28 lines (20 loc) · 740 Bytes
/
Example1.js
File metadata and controls
28 lines (20 loc) · 740 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
/**
* It is an expression that makes it possible to extract data, both from arrays and object properties, in different variables.
*/
//Reusing the example to list all fullnames
let people = [
{name: "Douglas", lastname: "Hernandez", gender: "Male", age: 22},
{name: "Pedro", lastname: "Gomez", gender: "Male", age: 22},
]
const listFullnames = () => {
let fullnames = people.map(element => {
//It pulls out only name and lastname, and assign them to both variables
let {name, lastname} = element;
console.log(name);
console.log(lastname);
let fullname = `${name} ${lastname}`;
return {name, lastname};
});
console.log(fullnames);
}
listFullnames();