I'm looking an alternatives to the following, I'm pretty new in javascritpt:
var values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].
I'm looking an alternatives to the following, I'm pretty new in javascritpt:
var values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].
You can use Array.fill()
:
const array = Array(10).fill(0)
or Array.from()
:
const array = Array.from(Array(10), a => 0);
You can use a simple for loop:
var res = [];
for (var i = 1; i <= 10; i++) {
res.push(0);
}
or this:
var res = Array(10).fill(0)