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

15 lines
388 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);
```
```js
initializeArrayWithValues(5, 2) // [2,2,2,2,2]
```