# @writetome51/array-replace-adjacent-items

> Better alternative to Array.splice() for replacing adjacent array items

Latest version **2.0.0** (published 2020-08-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @writetome51/array-replace-adjacent-items
pnpm add @writetome51/array-replace-adjacent-items
yarn add @writetome51/array-replace-adjacent-items
bun add @writetome51/array-replace-adjacent-items
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-08-24 |
| First published | 2018-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Steve Thompson |
| Maintainers | writetome51 |
| Keywords | array, manipulation, find, replace, items |

## Links

- npm: https://www.npmjs.com/package/@writetome51/array-replace-adjacent-items
- Repository: https://github.com/writetome51/array-replace-adjacent-items
- Homepage: https://github.com/writetome51/array-replace-adjacent-items#readme
- Issues: https://github.com/writetome51/array-replace-adjacent-items/issues
- npm.io page: https://npm.io/package/@writetome51/array-replace-adjacent-items

## Dependencies (2)

- [error-if-index-how-many-or-array-are-not-valid](https://npm.io/package/error-if-index-how-many-or-array-are-not-valid.md) ^2.0.1
- [error-if-array-too-short-to-meet-adjacent-items-request](https://npm.io/package/error-if-array-too-short-to-meet-adjacent-items-request.md) ^2.0.0

## Recent versions

- 2.0.0 (latest) — 2020-08-24
- 1.0.5 — 2019-04-14
- 1.0.4 — 2019-03-01
- 1.0.3 — 2019-02-09
- 1.0.2 — 2018-12-07
- 1.0.1 — 2018-10-10
- 1.0.0 — 2018-10-10

## README

# _replaceAdjacentItems(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;startingIndex,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;numItemsToReplace,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newValues: any[],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array<br>): void

Beginning at `startingIndex`, replaces adjacent `numItemsToReplace` with `newValues`, in `array`.   
`startingIndex` can be negative or positive.  
The number of items in `newValues` does not have to match `numItemsToReplace`.

## Examples
```
let arr = [1, 2, 3, 4, 5, 6, 7, 8];

_replaceAdjacentItems(0, 1, [30, 40], arr);
// arr is now [30, 40, 2, 3, 4, 5, 6, 7, 8]

arr = [1, 2, 3, 4, 5, 6, 7, 8];

_replaceAdjacentItems(3, 3, ['x'], arr);
// arr is now  [1, 2, 3, 'x', 7, 8];

arr = [1, 2, 3, 4, 5, 6, 7, 8];

_replaceAdjacentItems(-4, 2, ['x', 'y', 'z'], arr);
// arr is now  [1, 2, 3, 4, 'x', 'y', 'z', 7, 8];
```


## Installation
```bash
npm i @writetome51/array-replace-adjacent-items
```

## Loading
```js
import { _replaceAdjacentItems } from '@writetome51/array-replace-adjacent-items';
```

---
_Source: https://npm.io/package/@writetome51/array-replace-adjacent-items · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
