title: Use Destructuring Assignment to Assign Variables from Objects
challengeType: 1
---
## Description
<sectionid='description'>
We saw earlier how spread operator can effectively spread, or unpack, the contents of the array.
We can do something similar with objects as well. <dfn>Destructuring assignment</dfn> is special syntax for neatly assigning values taken directly from an object to variables.
Consider the following ES5 code:
<blockquote>var voxel = {x: 3.6, y: 7.4, z: 6.54 };<br>var x = voxel.x; // x = 3.6<br>var y = voxel.y; // y = 7.4<br>var z = voxel.z; // z = 6.54</blockquote>
Here's the same assignment statement with ES6 destructuring syntax:
<blockquote>const { x, y, z } = voxel; // x = 3.6, y = 7.4, z = 6.54</blockquote>
If instead you want to store the values of <code>voxel.x</code> into <code>a</code>, <code>voxel.y</code> into <code>b</code>, and <code>voxel.z</code> into <code>c</code>, you have that freedom as well.
Use destructuring to obtain the average temperature for tomorrow from the input object <code>avgTemperatures</code>, and assign value with key <code>tomorrow</code> to <code>tempOfTomorrow</code> in line.
testString: getUserInput => assert(getUserInput('index').match(/\{\s*tomorrow\s*:\s*tempOfTomorrow\s*}\s*=\s*avgTemperatures/g),'destructuring with reassignment was used');