-
Notifications
You must be signed in to change notification settings - Fork 1
splice
wolfram77 edited this page Mar 27, 2020
·
21 revisions
Removes or replaces existing values.
array.splice(x, i, [n], ...vs);
// x: an array
// i: remove index
// n: no. of values to remove
// vs: values to insert
// --> [removed, array]
const array = require('extra-array');
var x = [1, 2, 3, 4, 5];
array.splice(x, 2);
// [ [ 3, 4, 5 ], [ 1, 2 ] ]
array.splice(x, 2, 2);
// [ [ 3, 4 ], [ 1, 2, 5 ] ]
array.splice(x, 2, 2, 30, 40);
// [ [ 3, 4 ], [ 1, 2, 30, 40, 5 ] ]