-1

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].

2 Answers2

0

You can use Array.fill() :

const array = Array(10).fill(0)

or Array.from() :

const array = Array.from(Array(10), a => 0);
EricLavault
  • 12,130
  • 3
  • 23
  • 45
-1

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)
Hamall
  • 283
  • 3
  • 13