0

Array destructuring is super useful:

var [a, b, c] = [1, 2, 8];

It looks like it was implemented into Javascript 1.7, but then removed with bug 1083498. Now according to this table it's not supported by any browser except Firefox! :(

I wish I could use it because I don't like having to create an extra unnecessary variable.

With destructuring:

var a, b, c;
var input = "1 2 8";
[a, b, c] = arr.split(" ");

Without destructuring:

var a, b, c;
var input = "1 2 8";
var inputArr = input.split(" ");
a = inputArr[0];
b = inputArr[1];
c = inputArr[2];

Is there a way to do this without the need to create the extra unneeded inputArr and draw from it multiple times?

brentonstrine
  • 21,694
  • 25
  • 74
  • 120

0 Answers0