1.1.0 • Published 2 years ago
f-array.splice v1.1.0
f-array.splice
F*** the array.splice
.
Installation
npm i f-array.splice
Usage
Mutable arrays:
import { arrayInsertAt, arrayRemoveAt } from 'f-array.splice';
const mutableArray = [1, 2, 3];
// Inserts [-1, -2] at index 2.
arrayInsertAt(mutableArray, 2, -1, -2);
// mutableArray: 1, 2, -1, -2, 3
// Remove the item at index 1.
arrayRemoveAt(mutableArray, 1);
// mutableArray: 1, -1, -2, 3
Immutable arrays:
import { pureArrayInsertAt, pureArrayRemoveAt, pureArraySet } from 'f-array.splice';
// Returns a new array with [-1, -2] inserted at index 2.
pureArrayInsertAt([1, 2, 3], 2, -1, -2);
// 1, 2, -1, -2, 3
// Returns a new array with an item removed at index 1.
pureArrayRemoveAt([1, 2, 3], 1);
// 1, 3
// Returns a new array with an item at index replaced with another item.
pureArraySet([1, 2, 3], 1, -2);
// 1, -2, 3