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
This is a new feature of JavaScript 1.7 called Destructuring assignment:
Unfortunately, according to this table of versions, JavaScript 1.7 has not been implemented in Chrome. But it should be there in:
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).