@extra-array/fill
Version:
Fills with given value.
53 lines (38 loc) • 1.35 kB
Markdown
Fills with given value.
[:package:](https://www.npmjs.com/package/@extra-array/fill)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/fill)
[:vhs:](https://asciinema.org/a/332044)
[:moon:](https://www.npmjs.com/package/@extra-array/fill.min)
[:scroll:](https://unpkg.com/@extra-array/fill/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Alternatives: [fill], [fill$].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```javascript
array.fill(x, v, [i], [I]);
// x: an array
// v: value
// i: start index (0)
// I: end index (X)
```
```javascript
const array = require("extra-array");
var x = [1, 2, 3, 4];
array.fill(x, 2);
// [ 2, 2, 2, 2 ]
array.fill(x, 2, 1);
// [ 1, 2, 2, 2 ]
array.fill(x, 2, 1, 3);
// [ 1, 2, 2, 4 ]
```
<br>
<br>
## References
- [Array.prototype.fill: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
- [_.fill: lodash](https://lodash.com/docs/4.17.15#fill)
- [immutable-iterable-prototype: @azu](https://github.com/azu/immutable-iterable-prototype)
[fill]: https://github.com/nodef/extra-array/wiki/fill
[fill$]: https://github.com/nodef/extra-array/wiki/fill$