0

I've to declare some variables and want to minify the code. Here is my current code:

let a = [0,0,0,0,0,0,0,0,0,0];
let b = [0,0,0,0,0,0,0,0,0,0];
let c = [0,0,0,0,0,0,0,0,0,0];

Is there a way to minify the code?

I tried the following, but it doesn't work:

  let a = b = c = [0,0,0,0,0,0,0,0,0,0];

or

  let a, b, c = [0,0,0,0,0,0,0,0,0,0];

or

  let a = [0,0,0,0,0,0,0,0,0,0];
  let b = a; // b becomes a pointer to "a"
  let c = a;
Codr
  • 368
  • 3
  • 12
  • `let a = [0,0,0,0], b = [...a], c = [...a]` – adiga May 17 '19 at 08:30
  • or you could do something [like](https://stackoverflow.com/questions/51831998/how-to-add-same-elements-to-javascript-array-n-times/51832006#51832006) `const [a, b, c] = Array.from({ length: 3 }, () => new Array(10).fill(0))`, though it seems a bit odd to have those multiple independant variables, maybe consider a larger array or an object which contains `a`, `b`, and `c` – CertainPerformance May 17 '19 at 08:31
  • Thank you adiga for your solution. IMHO "marked as duplicate" is wrong, even if I found the solution also somewhere on recommended page: the solutions are similar, but the questions are total different ;-) – Codr May 20 '19 at 12:46

0 Answers0