Files
30-seconds-of-code/snippets/initialize-array-with-values.md
2017-12-12 07:11:37 -05:00

254 B

Initialize array with values

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

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