0.2.0 • Published 5 years ago

replace-array v0.2.0

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

replace-array

Utility to replace items in arrays at specified index

NPM

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