--- id: 587d7b89367417b2b2512b49 title: Use Destructuring Assignment to Assign Variables from Objects challengeType: 1 videoUrl: '' localeTitle: Usar asignación de destrucción para asignar variables de objetos --- ## Description
Anteriormente vimos cómo el operador de propagación puede difundir o desempaquetar efectivamente el contenido de la matriz. Podemos hacer algo similar con los objetos también. La asignación de destrucción es una sintaxis especial para asignar cuidadosamente valores tomados directamente de un objeto a variables. Considere el siguiente código ES5:
var voxel = {x: 3.6, y: 7.4, z: 6.54};
var x = voxel.x; // x = 3.6
var y = voxel.y; // y = 7.4
var z = voxel.z; // z = 6.54
Aquí está la misma declaración de asignación con la sintaxis de desestructuración ES6:
const {x, y, z} = voxel; // x = 3.6, y = 7.4, z = 6.54
Si, por el contrario, desea almacenar los valores de voxel.x en a , voxel.y en b , y voxel.z en c , también tiene esa libertad.
const {x: a, y: b, z: c} = vóxel // a = 3.6, b = 7.4, c = 6.54
Puede leerlo como "obtener el campo x y copiar el valor en a ", y así sucesivamente.
## Instructions
Utilice la desestructuración para obtener la temperatura promedio para mañana desde el objeto de entrada AVG_TEMPERATURES , y asigne un valor con la clave tomorrow a tempOfTomorrow en línea.
## Tests
```yml tests: - text: getTempOfTmrw(AVG_TEMPERATURES) debe ser 79 testString: 'assert(getTempOfTmrw(AVG_TEMPERATURES) === 79, "getTempOfTmrw(AVG_TEMPERATURES) should be 79");' - text: Se utilizó desestructuración con reasignación. testString: 'getUserInput => assert(getUserInput("index").match(/\{\s*tomorrow\s*:\s*tempOfTomorrow\s*}\s*=\s*avgTemperatures/g),"destructuring with reassignment was used");' ```
## Challenge Seed
```js const AVG_TEMPERATURES = { today: 77.5, tomorrow: 79 }; function getTempOfTmrw(avgTemperatures) { "use strict"; // change code below this line const tempOfTomorrow = undefined; // change this line // change code above this line return tempOfTomorrow; } console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79 ```
## Solution
```js // solution required ```