views:

493

answers:

1

Really like that function.

$matches = array('12', 'watt');
list($value, $unit) = $matches;

Is there a Javascript equivalent of that?

+3  A: 

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

EDIT: actually it wouldn't surprise me if the V8 Javascript library (and thus Chrome) supports this. But don't count on it either :)

Nicolás
Neat! I really like all the cool stuff they've put into the new versions of Javascript! Just feels like we wont be able to use them for ages..
Znarkus