-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03-map-reloaded.js
49 lines (41 loc) · 1.09 KB
/
03-map-reloaded.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
const orders = [
{
customerName: "Nicolas",
total: 60,
delivered: true,
},
{
customerName: "Zulema",
total: 120,
delivered: false,
},
{
customerName: "Santiago",
total: 180,
delivered: true,
},
{
customerName: "Valentina",
total: 240,
delivered: true,
},
];
//estamos aqui transformando el array orginal a un array unico de numeros
const nuevo = orders.map(item => item.total)
console.log('original', orders);
console.log('luego del map', nuevo);
/* const nuevo2 = orders.map(item => {
item.tax = .19;
return item;
});
console.log('luego del map en el que agregamos un nuevo atributo sin modificar el arrayn original ', nuevo2);
console.log('original', orders); */
/// esta respuesta es para no modificar el objeto en memoria, es decir para no modificar el original al momento de agregar un nuevo atributo
const nuevo3 = orders.map(item => {
return {
...item,
tax: .19
};
});
console.log(' sin modificar el arrayn original ', nuevo3);
console.log('original', orders);