UNPKG

@extra-array/splice

Version:

Removes or replaces existing values.

53 lines (38 loc) 1.45 kB
Removes or replaces existing values. [:package:](https://www.npmjs.com/package/@extra-array/splice) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/splice) [:vhs:](https://asciinema.org/a/332136) [:moon:](https://www.npmjs.com/package/@extra-array/splice.min) [:scroll:](https://unpkg.com/@extra-array/splice/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Alternatives: [splice], [splice$]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.splice(x, i, [n], ...vs); // x: an array // i: remove index // n: number of values to remove (rest) // vs: values to insert ``` ```javascript const array = require("extra-array"); var x = [1, 2, 3, 4, 5]; array.splice(x, 2); // [ 1, 2 ] array.splice(x, 2, 2); // [ 1, 2, 5 ] array.splice(x, 2, 2, 30, 40); // [ 1, 2, 30, 40, 5 ] ``` <br> <br> ## References - [Array.prototype.splice: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) - [Array.removeAt: sugarjs](https://sugarjs.com/docs/#/Array/removeAt) - [immutable-iterable-prototype: @azu](https://github.com/azu/immutable-iterable-prototype) [splice]: https://github.com/nodef/extra-array/wiki/splice [splice$]: https://github.com/nodef/extra-array/wiki/splice$