Files
30-seconds-of-code/snippets/fill-array.md
Angelos Chalaris 4e3c5a4808 Create fill-array.md
2017-12-14 15:41:40 +02:00

11 lines
364 B
Markdown

### Fill array
Use `Array.map()` to map values between `start` (inclusive) and `end` (exclusive) to `value`.
Omit `start` to start at the first element and/or `end` to finish at the last.
```js
const fillArray = (arr, value, start = 0, end = arr.length) =>
arr.map((v,i) => i>=start && i<end ? value : v);
// fillArray([1,2,3,4],'8',1,3) -> [1,'8','8',4]
```