Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6247967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:58:19+00:00 2026-05-24T12:58:19+00:00

var a,b,c; var arr = [1,2,3]; [a,b,c] = arr; this code works perfectly in

  • 0
var a,b,c;
var arr = [1,2,3];
[a,b,c] = arr;

this code works perfectly in Firefox resulting a=1, b=2 and c=3,
but it doesn’t work in Chrome. Is it a Chrome bug or
it is not valid javascript code? (I failed to find it in javascript references)

How can I modify this code to make it suitable for Chrome, with minimum damage to it?
(I don’t really like to write a = arr[0]; b = arr[1]… or the same with arr.shift() all the time)

P.S. this is just an example code, in real code

I get the arr array from somewhere outside my code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:58:19+00:00Added an answer on May 24, 2026 at 12:58 pm

    This is a new feature of JavaScript 1.7 called Destructuring assignment:

    Destructuring assignment makes it possible to extract data from arrays or objects using a syntax that mirrors the construction of array and object literals.

    The object and array literal expressions provide an easy way to create ad-hoc packages of data. Once you’ve created these packages of data, you can use them any way you want to. You can even return them from functions.

    One particularly useful thing you can do with destructuring assignment is to read an entire structure in a single statement, although there are a number of interesting things you can do with them, as shown in the section full of examples that follows.

    You can use destructuring assignment, for example, to swap values:

    var a = 1;
    var b = 3;
    [a, b] = [b, a];
    

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

    Unfortunately, according to this table of versions, JavaScript 1.7 has not been implemented in Chrome. But it should be there in:

    • FireFox 2.0+
    • IE 9
    • Opera 11.50.

    Try it for yourself in this jsfiddle: http://jsfiddle.net/uBReg/

    I tested this on Chrome (failed), IE 8 (failed), and FireFox 5 (which worked, per the wiki table).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't find any information on this, but suppose I have var arr =
This is a really basic question but... I have some code like this var
Given this code: var arr = []; for (var i = 0; i <
How can I take this code <script> var arr = [<%= myArray %>+<%= my2Array
I have this code: val arr: Array[Int] = ... val largestIndex = { var
I have this PHP code - <?php for($i=1; $i<=1000; $i++) { $array=array(); $array[$i]=54*$i; $arr=array($array[$i].,);
This is the code: class Program { void Add2Array(object arr, object item) { if
I'm trying to exit a function when a required input is not valid... but
The video tag I'm building will not work in IE9. Its works ok in
Sorry if this has been answered already, but I could not find an appropriate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.