How to use destructuring assignment to define enumerations in ES6? : <p>You can use destructuring assignment to define enumerations in ES6 as follows:</p>

<pre class="lang-js prettyprint-override"><code>var [red, green, blue] = [0, 1, 2];
</code></pre>

<p>Instead, I'd like the right hand side of the destructuring assignment to be dynamic. For example:</p>

<pre class="lang-js prettyprint-override"><code>var MAX_ENUM_SIZE = 32;
var ENUM = new Array(MAX_ENUM_SIZE);
for (var i = 0; i &lt; MAX_ENUM_SIZE; i++) ENUM[i] = i;

var [red, green, blue] = ENUM;
</code></pre>

<p>Unfortunately, this seems like a hack. What if I want a bigger enumeration in the future? Hence, I was thinking of using destructuring assignment with an iterator as follows:</p>

<pre class="lang-js prettyprint-override"><code>var [red, green, blue] = enumeration(/* I don't want to specify size */);
</code></pre>

<p>However, I don't think it's possible to use destructuring assignment with iterators<sup>[citation needed]</sup>. Is there any way to accomplish this goal?</p>
