UNPKG

@extra-array/splice-update

Version:

Removes or replaces existing values.

59 lines (43 loc) 1.63 kB
Removes or replaces existing values. [:package:](https://www.npmjs.com/package/@extra-array/splice-update) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/splice-update) [:vhs:](https://asciinema.org/a/332135) [:moon:](https://www.npmjs.com/package/@extra-array/splice-update.min) [:scroll:](https://unpkg.com/@extra-array/splice-update/) [: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 (updated) // 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 ] x; // [ 1, 2 ] var x = [1, 2, 3, 4, 5]; array.splice$(x, 2, 2); // [ 1, 2, 5 ] var x = [1, 2, 3, 4, 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) - [Array.insert: sugarjs](https://sugarjs.com/docs/#/Array/insert) - [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$