@extra-array/copy
Version:
Copies part of array to another.
60 lines (44 loc) • 1.69 kB
Markdown
Copies part of array to another.
[:package:](https://www.npmjs.com/package/@extra-array/copy)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/copy)
[:vhs:](https://asciinema.org/a/332030)
[:moon:](https://www.npmjs.com/package/@extra-array/copy.min)
[:scroll:](https://unpkg.com/@extra-array/copy/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Alternatives: [copy], [copy$].<br>
> Similar: [copy], [copyWithin], [moveWithin].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```javascript
array.copy(x, y, [j], [i], [I]);
// x: target array
// y: source array
// j: write index (0)
// i: read start index (0)
// I: read end index (X)
```
```javascript
const array = require("extra-array");
var x = [1, 2, 3, 4, 5];
var y = [10, 20, 30];
array.copy(x, y);
// [ 10, 20, 30, 4, 5 ]
array.copy(x, y, 1);
// [ 1, 10, 20, 30, 5 ]
array.copy(x, y, 1, 1);
// [ 1, 20, 30, 4, 5 ]
array.copy(x, y, 1, 1, 2);
// [ 1, 20, 3, 4, 5 ]
```
<br>
<br>
## References
- [Array.prototype.copyWithin: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
- [Collections.copy: Java](https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#copy(java.util.List,%20java.util.List))
[copy]: https://github.com/nodef/extra-array/wiki/copy
[copy$]: https://github.com/nodef/extra-array/wiki/copy$
[copyWithin]: https://github.com/nodef/extra-array/wiki/copyWithin
[moveWithin]: https://github.com/nodef/extra-array/wiki/moveWithin