10 lines
304 B
Markdown
10 lines
304 B
Markdown
### 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 `value` to use a default value of `0`.
|
|
|
|
```js
|
|
const initializeArray = (n, value = 0) => Array(n).fill(value);
|
|
// initializeArray(5, 2) -> [2,2,2,2,2]
|
|
```
|