Files
30-seconds-of-code/snippets/initializeArrayWithValues.md
Stefan Feješ 82b850fd00 Fix test cases
2017-12-17 22:26:07 +01:00

12 lines
380 B
Markdown

### 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`.
```js
const initializeArrayWithValues = (n, value = 0) => Array(n).fill(value);
// initializeArrayWithValues(5, 2) -> [2,2,2,2,2]
```