Splices arrays at multiple positions and returns both the array and the removed elements for easier chaining.
constarray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
// remove the first two elements multisplice(array, [0, 1], 1)
//optionally destructure the return to extract removed elements const {removed} = multisplice(array, [0, 1], 1)
// using chaining // unlike splice you can pick whether you want the array or the removed elements multisplice(array, [0, 1], 1).array .filter(() => {...}) .map(() => {...})
// delete 10000 items at position 9 = OK (because splice allows it) // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] // [...
You can also insert items. By default they are inserted as they are at each index position passed. Use the insert option if you want to match the items in an array of items to each index position. See MULTISPLICE_ITEM for details.
The function's types are setup to only take items to insert of the same type that the array already contains, so it will complain depending on what insert option you use. You can always cast the item/s as any and/or pass a different type for the TArray type parameter.
Splices arrays at multiple positions and returns both the array and the removed elements for easier chaining.
Deleting more than one item at a time at multiple positions is supported if the ranges created don't overlaps:
You can also insert items. By default they are inserted as they are at each index position passed. Use the
insert
option if you want to match the items in an array of items to each index position. See MULTISPLICE_ITEM for details.The function's types are setup to only take items to insert of the same type that the array already contains, so it will complain depending on what insert option you use. You can always cast the item/s as any and/or pass a different type for the TArray type parameter.