Files
30-seconds-of-code/snippets/initialize-array-with-value.md
Angelos Chalaris 466325da13 Array initialization
2017-11-30 20:06:16 +02:00

251 B

Initialize array with values

Use Array(n) to create an array of the desired length, fill(v) to fill it with the desired value. You can omit v to use a default value of 0.

var initializeArray = (n, v = 0) =>
  Array(n).fill(v);