Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1116571 of Destructuring assignment

  • Revision slug: Web/JavaScript/Reference/Operators/Destructuring_assignment
  • Revision title: Destructuring assignment
  • Revision id: 1116571
  • Created:
  • Creator: torazaburo
  • Is current revision? No
  • Comment

Revision Content

{{jsSidebar("Operators")}}

The destructuring assignment syntax is a JavaScript expression that makes it possible to extract data from arrays or objects into distinct variables.

Syntax

var a, b, rest;
[a, b] = [1, 2];
console.log(a); // 1
console.log(b); // 2

[a, b, ...rest] = [1, 2, 3, 4, 5];
console.log(a); // 1
console.log(b); // 2
console.log(rest); // [3, 4, 5]

({a, b} = {a:1, b:2});
console.log(a); // 1
console.log(b); // 2

({a, b, ...rest} = {a:1, b:2, c:3, d:4}); 
// ES7 - not implemented in Firefox 47a01

Description

The object and array literal expressions provide an easy way to create ad hoc packages of data.

var x = [1, 2, 3, 4, 5];

The destructuring assignment uses similar syntax, but on the left-hand side of the assignment to define what elements to extract from the sourced variable.

var x = [1, 2, 3, 4, 5];
var [y, z] = x;
console.log(y); // 1
console.log(z); // 2

This capability is similar to features present in languages such as Perl and Python.

Array destructuring

Basic variable assignment

var foo = ["one", "two", "three"];

var [one, two, three] = foo;
console.log(one); // "one"
console.log(two); // "two"
console.log(three); // "three"

Assignment separate from declaration

A variable can be assigned its value via destructuring separate from the variable's declaration.

var a, b;

[a, b] = [1, 2];
console.log(a); // 1
console.log(b); // 2

Default values

A variable can be assigned a default, in the case that the value pulled from the array is undefined.

var a, b;

[a=5, b=7] = [1];
console.log(a); // 1
console.log(b); // 7

Swapping variables

Two variables values can be swapped in one destructuring expression.

Without destructuring assignment, swapping two values requires a temporary variable (or, in some low-level languages, the XOR-swap trick).

var a = 1;
var b = 3;

[a, b] = [b, a];
console.log(a); // 3
console.log(b); // 1

Parsing an array returned from a function

It's always been possible to return an array from a function. Destructuring can make working with an array return value more concise.

In this example, f() returns the values [1, 2] as its output, which can be parsed in a single line with destructuring.

function f() {
  return [1, 2];
}

var a, b; 
[a, b] = f(); 
console.log(a); // 1
console.log(b); // 2

Ignoring some returned values

You can ignore return values that you're not interested in:

function f() {
  return [1, 2, 3];
}

var [a, , b] = f();
console.log(a); // 1
console.log(b); // 3

You can also ignore all returned values:

[,,] = f();

Pulling values from a regular expression match

When the regular expression exec() method finds a match, it returns an array containing first the entire matched portion of the string and then the portions of the string that matched each parenthesized group in the regular expression. Destructuring assignment allows you to pull the parts out of this array easily, ignoring the full match if it is not needed.

var url = "https://developer.mozilla.org/en-US/Web/JavaScript";

var parsedURL = /^(\w+)\:\/\/([^\/]+)\/(.*)$/.exec(url);
console.log(parsedURL); // ["https://developer.mozilla.org/en-US/Web/JavaScript", "https", "developer.mozilla.org", "en-US/Web/JavaScript"]

var [, protocol, fullhost, fullpath] = parsedURL;

console.log(protocol); // "https"

Object destructuring

Basic assignment

var o = {p: 42, q: true};
var {p, q} = o;

console.log(p); // 42
console.log(q); // true 

Assignment without declaration

A variable can be assigned its value with destructuring separate from its declaration.

var a, b;

({a, b} = {a:1, b:2});

The ( .. ) around the assignment statement is required syntax when using object literal destructuring assignment without a declaration.

{a, b} = {a:1, b:2} is not valid stand-alone syntax, as the {a, b} on the left-hand side is considered a block and not an object literal.

However, ({a, b} = {a:1, b:2}) is valid, as is var {a, b} = {a:1, b:2}

Assigning to new variable names

A variable can be extracted from an object and assigned to a variable with a different name than the object property.

var o = {p: 42, q: true};
var {p: foo, q: bar} = o;
 
console.log(foo); // 42 
console.log(bar); // true  

Default values

A variable can be assigned a default, in the case that the value pulled from the object is undefined.

var {a=10, b=5} = {a: 3};

console.log(a); // 3
console.log(b); // 5

Setting a function parameter's default value

ES5 version

function drawES5Chart(options) {
  options = options === undefined ? {} : options;
  var size = options.size === undefined ? 'big' : options.size;
  var cords = options.cords === undefined ? { x: 0, y: 0 } : options.cords;
  var radius = options.radius === undefined ? 25 : options.radius;
  console.log(size, cords, radius);
  // now finally do some chart drawing
}

drawES5Chart({
  cords: { x: 18, y: 30 },
  radius: 30
});

ES6 version

function drawES6Chart({size = 'big', cords = { x: 0, y: 0 }, radius = 25} = {}) {
  console.log(size, cords, radius);
  // do some chart drawing
}

// In Firefox, default values for destructuring assignments are not yet implemented (as described below). 
// The workaround is to write the parameters in the following way:
// ({size: size = 'big', cords: cords = { x: 0, y: 0 }, radius: radius = 25} = {})

drawES6Chart({
  cords: { x: 18, y: 30 },
  radius: 30
});

In Firefox, default values for destructuring assignments are not yet implemented: var { x = 3 } = {} and var [foo = "bar"] = []. See {{bug(932080)}} for destructured default values in functions.

Module (non-ES6) loading

Destructuring can help to load specific subsets of a non-ES6 module like here in the Add-on SDK:

const { Loader, main } = require('toolkit/loader');

The import statement in ES6 has a superficial resemablance to destructuring, but is actually completely unrelated.

Nested object and array destructuring

var metadata = {
    title: "Scratchpad",
    translations: [
       {
        locale: "de",
        localization_tags: [ ],
        last_edit: "2014-04-14T08:43:37",
        url: "/de/docs/Tools/Scratchpad",
        title: "JavaScript-Umgebung"
       }
    ],
    url: "/en-US/docs/Tools/Scratchpad"
};

var { title: englishTitle, translations: [{ title: localeTitle }] } = metadata;

console.log(englishTitle); // "Scratchpad"
console.log(localeTitle);  // "JavaScript-Umgebung"

For of iteration and destructuring

var people = [
  {
    name: "Mike Smith",
    family: {
      mother: "Jane Smith",
      father: "Harry Smith",
      sister: "Samantha Smith"
    },
    age: 35
  },
  {
    name: "Tom Jones",
    family: {
      mother: "Norah Jones",
      father: "Richard Jones",
      brother: "Howard Jones"
    },
    age: 25
  }
];

for (var {name: n, family: { father: f } } of people) {
  console.log("Name: " + n + ", Father: " + f);
}

// "Name: Mike Smith, Father: Harry Smith"
// "Name: Tom Jones, Father: Richard Jones"

Pulling fields from objects passed as function parameter

function userId({id}) {
  return id;
}

function whois({displayName: displayName, fullName: {firstName: name}}){
  console.log(displayName + " is " + name);
}

var user = { 
  id: 42, 
  displayName: "jdoe",
  fullName: { 
      firstName: "John",
      lastName: "Doe"
  }
};

console.log("userId: " + userId(user)); // "userId: 42"
whois(user); // "jdoe is John"

This pulls the id, displayName and firstName from the user object and prints them.

Computed object property names and destructuring

Computed property names, like on object literals, can be used with destructuring.

let key = "z";
let { [key]: foo } = { z: "bar" };

console.log(foo); // "bar"

Specifications

Specification Status Comment
{{SpecName('ES6', '#sec-destructuring-assignment', 'Destructuring assignment')}} {{Spec2('ES6')}} Initial definition.
{{SpecName('ESDraft', '#sec-destructuring-assignment', 'Destructuring assignment')}} {{Spec2('ESDraft')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Edge Internet Explorer Opera Safari
Basic support {{CompatChrome(49.0)}} {{ CompatGeckoDesktop("1.8.1") }} 14 {{CompatNo}} {{CompatNo}} 7.1
Computed property names {{CompatChrome(49.0)}} {{ CompatGeckoDesktop("34") }} 14 {{CompatNo}} {{CompatNo}} {{CompatNo}}
Spread operator {{CompatChrome(49.0)}} {{ CompatGeckoDesktop("34") }} 12[1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatNo}} {{CompatChrome(49.0)}} {{ CompatGeckoMobile("1.0") }} {{CompatNo}} {{CompatNo}} 8 {{CompatChrome(49.0)}}
Computed property names {{CompatNo}} {{CompatChrome(49.0)}} {{ CompatGeckoMobile("34") }} {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatChrome(49.0)}}
Spread operator {{CompatNo}} {{CompatChrome(49.0)}} {{ CompatGeckoMobile("34") }} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatChrome(49.0)}}

[1] Requires "Enable experimental Javascript features" to be enabled under `about:flags`

Firefox-specific notes

  • Firefox provided a non-standard language extension in JS1.7 for destructuring. This extension has been removed in Gecko 40 {{geckoRelease(40)}}. See {{bug(1083498)}}.
  • Starting with Gecko 41 {{geckoRelease(41)}} and to comply with the ES6 specification, parenthesized destructuring patterns, like ([a, b]) = [1, 2] or ({a, b}) = { a: 1, b: 2 }, are now considered invalid and will throw a {{jsxref("SyntaxError")}}. See Jeff Walden's blog post and {{bug(1146136)}} for more details.

See also

Revision Source

<div>{{jsSidebar("Operators")}}</div>

<p>The <strong>destructuring assignment</strong> syntax is a JavaScript expression that makes it possible to extract data from arrays or objects into distinct variables.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="brush:js">
var a, b, rest;
[a, b] = [1, 2];
console.log(a); // 1
console.log(b); // 2

[a, b, ...rest] = [1, 2, 3, 4, 5];
console.log(a); // 1
console.log(b); // 2
console.log(rest); // [3, 4, 5]

({a, b} = {a:1, b:2});
console.log(a); // 1
console.log(b); // 2

({a, b, ...rest} = {a:1, b:2, c:3, d:4}); 
// ES7 - not implemented in Firefox 47a01
</pre>

<h2 id="Description">Description</h2>

<p>The object and array literal expressions provide an easy way to create <em>ad&nbsp;hoc</em> packages of data.</p>

<pre class="brush: js">
var x = [1, 2, 3, 4, 5];</pre>

<p>The destructuring assignment uses similar syntax, but on the left-hand side of the assignment&nbsp;to define what elements to extract from the sourced variable.</p>

<pre class="brush: js">
var x = [1, 2, 3, 4, 5];
var [y, z] = x;
console.log(y); // 1
console.log(z); // 2
</pre>

<p>This capability is similar to features present in languages such as Perl and Python.</p>

<h2 id="Array_destructuring">Array destructuring</h2>

<h3 id="Basic_variable_assignment">Basic variable assignment</h3>

<pre class="brush: js">
var foo = ["one", "two", "three"];

var [one, two, three] = foo;
console.log(one); // "one"
console.log(two); // "two"
console.log(three); // "three"
</pre>

<h3 id="Assignment_separate_from_declaration">Assignment separate from declaration</h3>

<p>A variable can be assigned its value via destructuring separate from the variable's declaration.</p>

<pre class="brush:js">
var a, b;

[a, b] = [1, 2];
console.log(a); // 1
console.log(b); // 2
</pre>

<h3 id="Default_values">Default values</h3>

<p>A&nbsp;variable can be assigned a default, in the case that the value pulled from the array is <code>undefined</code>.</p>

<pre class="brush: js">
var a, b;

[a=5, b=7] = [1];
console.log(a); // 1
console.log(b); // 7
</pre>

<h3 id="Swapping_variables">Swapping variables</h3>

<p>Two variables values can be swapped in one destructuring expression.</p>

<p>Without destructuring assignment, swapping two values requires a temporary variable (or, in some low-level languages, the <a class="external" href="https://en.wikipedia.org/wiki/XOR_swap">XOR-swap trick</a>).</p>

<pre class="brush:js">
var a = 1;
var b = 3;

[a, b] = [b, a];
console.log(a); // 3
console.log(b); // 1
</pre>

<h3 id="Parsing_an_array_returned_from_a_function">Parsing an array&nbsp;returned&nbsp;from a function</h3>

<p>It's always been possible to return an array from a function. Destructuring can make&nbsp;working&nbsp;with an array return value more concise.</p>

<p>In this example, <code>f()</code> returns the values <code>[1, 2]</code> as its output, which can be parsed in a single line with destructuring.</p>

<pre class="brush:js">
function f() {
  return [1, 2];
}

var a, b; 
[a, b] = f(); 
console.log(a); // 1
console.log(b); // 2
</pre>

<h3 id="Ignoring_some_returned_values">Ignoring some returned values</h3>

<p>You can ignore return values that you're not interested in:</p>

<pre class="brush:js">
function f() {
  return [1, 2, 3];
}

var [a, , b] = f();
console.log(a); // 1
console.log(b); // 3
</pre>

<p>You&nbsp;can also ignore&nbsp;all&nbsp;returned values:</p>

<pre class="brush:js">
[,,] = f();
</pre>

<h3 id="Pulling_values_from_a_regular_expression_match">Pulling values from a regular expression match</h3>

<p>When the regular expression <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec"> exec()</a></code> method finds a match, it returns an array containing first the entire matched portion of the string and then the portions of the string that matched each parenthesized group in the regular expression. Destructuring assignment allows you to pull the parts out of this array easily, ignoring the full match if it is not needed.</p>

<pre class="brush:js">
var url = "https://developer.mozilla.org/en-US/Web/JavaScript";

var parsedURL = /^(\w+)\:\/\/([^\/]+)\/(.*)$/.exec(url);
console.log(parsedURL); // ["https://developer.mozilla.org/en-US/Web/JavaScript", "https", "developer.mozilla.org", "en-US/Web/JavaScript"]

var [, protocol, fullhost, fullpath] = parsedURL;

console.log(protocol); // "https"
</pre>

<h2 id="Object_destructuring">Object destructuring</h2>

<h3 id="Basic_assignment">Basic assignment</h3>

<pre class="brush: js">
var o = {p: 42, q: true};
var {p, q} = o;

console.log(p); // 42
console.log(q); // true 
</pre>

<h3 id="Assignment_without_declaration">Assignment without declaration</h3>

<p>A variable can be assigned its value with destructuring separate from its declaration.</p>

<pre class="brush:js">
var a, b;

({a, b} = {a:1, b:2});</pre>

<div class="note">
<p>The <code>( .. )</code> around the assignment statement is required syntax when using object literal destructuring assignment without a declaration.</p>

<p><code>{a, b} = {a:1, b:2}</code> is not valid stand-alone&nbsp;syntax, as the <code>{a, b}</code> on the left-hand side is&nbsp;considered&nbsp;a block and not an object literal.</p>

<p>However, <code>({a, b} = {a:1, b:2})</code>&nbsp;is valid, as is&nbsp;<code>var {a, b} = {a:1, b:2}</code></p>
</div>

<h3 id="Assigning_to_new_variable_names">Assigning to new variable names</h3>

<p>A variable can be extracted from an object and assigned to a variable with a different name than the object property.</p>

<pre class="brush: js">
var o = {p: 42, q: true};
var {p: foo, q: bar} = o;
 
console.log(foo); // 42 
console.log(bar); // true &nbsp;</pre>

<h3 id="Default_values_2">Default values</h3>

<p>A&nbsp;variable can be assigned a default, in the case that the value pulled from the object is <code>undefined</code>.</p>

<pre class="brush: js">
var {a=10, b=5} = {a: 3};

console.log(a); // 3
console.log(b); // 5</pre>

<h3 id="Setting_a_function_parameter's_default_value">Setting a function parameter's&nbsp;default value</h3>

<h4 id="ES5_version">ES5 version</h4>

<pre class="brush: js">
function drawES5Chart(options) {
  options = options === undefined ? {} : options;
  var size = options.size === undefined ? 'big' : options.size;
  var cords = options.cords === undefined ? { x: 0, y: 0 } : options.cords;
  var radius = options.radius === undefined ? 25 : options.radius;
  console.log(size, cords, radius);
  // now finally do some chart drawing
}

drawES5Chart({
  cords: { x: 18, y: 30 },
  radius: 30
});</pre>

<h4 id="ES6_version">ES6 version</h4>

<pre class="brush: js">
function drawES6Chart({size = 'big', cords = { x: 0, y: 0 }, radius = 25} = {}) {
  console.log(size, cords, radius);
  // do some chart drawing
}

// In Firefox, default values for destructuring assignments are not yet implemented (as described below). 
// The workaround is to write the parameters in the following way:
// ({size: size = 'big', cords: cords = { x: 0, y: 0 }, radius: radius = 25} = {})

drawES6Chart({
  cords: { x: 18, y: 30 },
  radius: 30
});</pre>

<div class="note">
<p>In Firefox, default values for destructuring assignments are not yet implemented: var { x = 3 } = {} and var [foo = "bar"] = []. See {{bug(932080)}} for destructured default values in functions.</p>
</div>

<h3 id="Module_(non-ES6)_loading">Module (non-ES6) loading</h3>

<p>Destructuring can help to load specific subsets of a non-ES6 module like here in the <a href="/en-US/Add-ons/SDK">Add-on SDK</a>:</p>

<pre class="brush: js">
const { Loader, main } = require('toolkit/loader');
</pre>

<div class="note">
<p>The <code>import</code> statement in ES6&nbsp;has a superficial resemablance to&nbsp;destructuring, but is actually completely unrelated.</p>
</div>

<h3 id="Nested_object_and_array_destructuring">Nested object and array destructuring</h3>

<pre class="brush:js">
var metadata = {
&nbsp;&nbsp;&nbsp; title: "Scratchpad",
&nbsp;&nbsp;&nbsp; translations: [
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; locale: "de",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; localization_tags: [ ],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last_edit: "2014-04-14T08:43:37",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url: "/de/docs/Tools/Scratchpad",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; title: "JavaScript-Umgebung"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; ],
&nbsp;&nbsp;&nbsp; url: "/en-US/docs/Tools/Scratchpad"
};

var { title: englishTitle, translations: [{ title: localeTitle }] } = metadata;

console.log(englishTitle); // "Scratchpad"
console.log(localeTitle);&nbsp; // "JavaScript-Umgebung"</pre>

<h3 id="For_of_iteration_and_destructuring">For of iteration and destructuring</h3>

<pre class="brush: js">
var people = [
&nbsp; {
&nbsp;&nbsp;&nbsp; name: "Mike Smith",
&nbsp;&nbsp;&nbsp; family: {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mother: "Jane Smith",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; father: "Harry Smith",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sister: "Samantha Smith"
&nbsp;&nbsp;&nbsp; },
&nbsp;&nbsp;&nbsp; age: 35
&nbsp; },
&nbsp; {
&nbsp;&nbsp;&nbsp; name: "Tom Jones",
&nbsp;&nbsp;&nbsp; family: {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mother: "Norah Jones",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; father: "Richard Jones",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; brother: "Howard Jones"
&nbsp;&nbsp;&nbsp; },
&nbsp;&nbsp;&nbsp; age: 25
&nbsp; }
];

for (var {name: n, family: { father: f } } of people) {
  console.log("Name: " + n + ", Father: " + f);
}

// "Name: Mike Smith, Father: Harry Smith"
// "Name: Tom Jones, Father: Richard Jones"</pre>

<h3 id="Pulling_fields_from_objects_passed_as_function_parameter">Pulling fields from objects passed as function parameter</h3>

<pre class="brush:js">
function userId({id}) {
  return id;
}

function whois({displayName: displayName, fullName: {firstName: name}}){
  console.log(displayName + " is " + name);
}

var user = { 
  id: 42, 
  displayName: "jdoe",
  fullName: { 
      firstName: "John",
      lastName: "Doe"
  }
};

console.log("userId: " + userId(user)); // "userId: 42"
whois(user); // "jdoe is John"</pre>

<p>This pulls the <code>id</code>, <code>displayName</code> and <code>firstName</code> from the user object and prints them.</p>

<h3 id="Computed_object_property_names_and_destructuring">Computed object property names and destructuring</h3>

<p>Computed property names, like on <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names">object literals</a>, can be used with destructuring.</p>

<pre class="brush: js">
let key = "z";
let { [key]: foo } = { z: "bar" };

console.log(foo); // "bar"
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-destructuring-assignment', 'Destructuring assignment')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-destructuring-assignment', 'Destructuring assignment')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Edge</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(49.0)}}</td>
   <td>{{ CompatGeckoDesktop("1.8.1") }}</td>
   <td>14</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>7.1</td>
  </tr>
  <tr>
   <td>Computed property names</td>
   <td>{{CompatChrome(49.0)}}</td>
   <td>{{ CompatGeckoDesktop("34") }}</td>
   <td>14</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td>Spread operator</td>
   <td>{{CompatChrome(49.0)}}</td>
   <td>{{ CompatGeckoDesktop("34") }}</td>
   <td>12<sup>[1]</sup></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(49.0)}}</td>
   <td>{{ CompatGeckoMobile("1.0") }}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>8</td>
   <td>{{CompatChrome(49.0)}}</td>
  </tr>
  <tr>
   <td>Computed property names</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(49.0)}}</td>
   <td>{{ CompatGeckoMobile("34") }}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(49.0)}}</td>
  </tr>
  <tr>
   <td>Spread operator</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(49.0)}}</td>
   <td>{{ CompatGeckoMobile("34") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(49.0)}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Requires&nbsp;"Enable experimental Javascript features" to be enabled&nbsp;under `about:flags`</p>

<h2 id="Firefox-specific_notes">Firefox-specific notes</h2>

<ul>
 <li>Firefox provided a non-standard language extension in <a href="/en-US/docs/Web/JavaScript/New_in_JavaScript/1.7">JS1.7</a> for destructuring. This extension has been removed in Gecko 40 {{geckoRelease(40)}}. See {{bug(1083498)}}.</li>
 <li>Starting with Gecko 41 {{geckoRelease(41)}} and to comply with the ES6 specification, parenthesized destructuring patterns, like <code>([a, b]) = [1, 2]</code> or <code>({a, b}) = { a: 1, b: 2 }</code>, are now considered invalid and will throw a {{jsxref("SyntaxError")}}. See <a class="external external-icon" href="https://whereswalden.com/2015/06/20/new-changes-to-make-spidermonkeys-and-firefoxs-parsing-of-destructuring-patterns-more-spec-compliant/">Jeff Walden's blog post</a> and {{bug(1146136)}} for more details.</li>
</ul>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators">Assignment operators</a></li>
 <li><a href="https://hacks.mozilla.org/2015/05/es6-in-depth-destructuring/">"ES6 in Depth: Destructuring" on hacks.mozilla.org</a></li>
</ul>
Revert to this revision