'Best way to create array of ten 0 in javascript [duplicate]
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].
Solution 1:[1]
You can use Array.fill() :
const array = Array(10).fill(0)
or Array.from() :
const array = Array.from(Array(10), a => 0);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
