Skip to content

felamaslen/replace-array

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published