I am looking for a less verbose way to instantiate multiple variables to the same value. I currently have this:
let a = 0;
let b = 0;
let c = 0;
let d = 0;
let e = 0;
let f = 0;
let g = 0;
let h = 0;
let i = 0;
let j = 0;
let k = 0;
let l = 0;
let m = 0;
let n = 0;
let o = 0;
And I am looking to do something like this:
let { a, b, c, d, e, f, g, h, i, j, k, l, m, n, o } = 0;
All these variables return undefined
. There surely has to be a better way to instantiate multiple variables to the same value? I am using let
as these values change over time.
You could destructure your variables as an array as follows, though you need to know the number of elements, and it does require ES6+:
let [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o] = Array(15).fill(0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With