--- id: 587d7b89367417b2b2512b4a title: Use Destructuring Assignment to Assign Variables from Nested Objects challengeType: 1 videoUrl: '' localeTitle: 使用解构分配从嵌套对象分配变量 --- ## Description
我们可以类似地将嵌套对象解构为变量。请考虑以下代码:
const a = {
开始:{x:5,y:6},
结束:{x:6,y:-9}
};
const {start:{x:startX,y:startY}} = a;
console.log(startX,startY); // 5,6
在上面的示例中,变量start被赋予a.start的值,该值也是一个对象。
## Instructions
用解构赋值来获得maxforecast.tomorrow并将其分配给maxOfTomorrow
## Tests
```yml tests: - text: maxOfTomorrow等于84.6 testString: 'assert(getMaxOfTmrw(LOCAL_FORECAST) === 84.6, "maxOfTomorrow equals 84.6");' - text: 使用嵌套解构 testString: 'getUserInput => assert(getUserInput("index").match(/\{\s*tomorrow\s*:\s*\{\s*max\s*:\s*maxOfTomorrow\s*\}\s*\}\s*=\s*forecast/g),"nested destructuring was used");' ```
## Challenge Seed
```js const LOCAL_FORECAST = { today: { min: 72, max: 83 }, tomorrow: { min: 73.3, max: 84.6 } }; function getMaxOfTmrw(forecast) { "use strict"; // change code below this line const maxOfTomorrow = undefined; // change this line // change code above this line return maxOfTomorrow; } console.log(getMaxOfTmrw(LOCAL_FORECAST)); // should be 84.6 ```
## Solution
```js // solution required ```