Javascript equivalent of PHP's list()

There is, in 'newer' versions of Javascript: Destructuring assignment - Javascript 1.7. It's probably only supported in Mozilla-based browsers, and maybe in Rhino.

var a = 1;  
var b = 3;  

[a, b] = [b, a];  

EDIT: actually it wouldn't surprise me if the V8 Javascript library (and thus Chrome) supports this. But don't count on it either Now supported in all modern browsers(except IE, of course).


try this:

matches = ['12', 'watt'];
[value, unit] = matches; 

ES6 does support this directly now via array destructuring.

const matches = ['12', 'watt'];
const [value, unit] = matches;