A function is specified that returns an array with (n) elements. I want to assign these return values, but not the first.
// match returns ["abc123","abc","123"] here
[ foo, bar ] = "abc123".match(/([a-z]*)([0-9]*)/);
Now I have
foo = "abc123"
bar = "abc"
But my intention was
foo = "abc"
bar = "123"
In other languages you can do things like
[_,foo,bar] = "abc123".match(/([a-z]*)([0-9]*)/);
To archive this, but how is this done in JS?
Of course one could do
[garbage,foo,bar] = "abc123".match(/([a-z]*)([0-9]*)/);
garbage = undefined;
.. but, .. urgh ..
source
share