replace-array
v0.2.0
Published
Replace or remove items in JavaScript arrays
Downloads
2
Readme
replace-array
Utility to replace items in arrays at specified index
Install
yarn add replace-array
Usage
replaceAtIndex
import { replaceAtIndex } from 'replace-array';
const replaced = replaceAtIndex([1, 2, 3], 1, 5); // -> [1, 5, 3]
const replacedFn = replaceAtIndex([1, 2, 3], 1, value => value * 3); // -> [1, 6, 3]
const replacedPadded = replaceAtIndex([1, 2], 3, 10, 0); // -> [1, 2, 0, 10]
removeAtIndex
import { removeAtIndex } from 'replace-array';
const removed = removeAtIndex([1, 2, 3], 1); // -> [1, 3]
License
MIT © felamaslen