Given: a = [[1,2],[3,4],]
I want to do something like:
a = [for ([x,y] of a) [x*2,y]];
But this gives me the next error:
'SyntaxError: missing variable name'
I am able to do the following:
a = [for (z of a) [z[0]*2,z[1]]];
I prefer the first notation as the internal variables (x and y) can be given descriptive names making the code easier to read. Is it possible?
array comprehensionsis non-standard in Javascript. For future-facing usages, consider using Array.prototype.map, Array.prototype.filter, arrow functions, and spread syntax.