Update snippet descriptions

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-20 23:02:01 +03:00
parent 52880f08ee
commit caa67e2a49
63 changed files with 175 additions and 126 deletions

View File

@ -1,15 +1,16 @@
---
title: initializeArrayWithValues
tags: array,math,intermediate
tags: array,intermediate
---
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 `val` to use a default value of `0`.
- Use `Array.from()` to create an array of the desired length, `Array.prototype.fill()` to fill it with the desired values.
- Omit the last argument, `val`, to use a default value of `0`.
```js
const initializeArrayWithValues = (n, val = 0) => Array(n).fill(val);
const initializeArrayWithValues = (n, val = 0) =>
Array.from({ length: n }).fill(val);
```
```js