Files
30-seconds-of-code/snippets/initializeArrayWithValues.md
Angelos Chalaris bb722b2eb4 Updated examples
2017-12-27 16:35:25 +02:00

388 B

initializeArrayWithValues

Initializes and fills an array with the specified values.

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

const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value);
initializeArrayWithValues(5, 2) // [2,2,2,2,2]