Update snippet descriptions
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user