https://github.com/writetome51/array-insert-at
Function that inserts new items at a specified index in the array
https://github.com/writetome51/array-insert-at
array-manipulations insert items javascript new typescript
Last synced: 5 months ago
JSON representation
Function that inserts new items at a specified index in the array
- Host: GitHub
- URL: https://github.com/writetome51/array-insert-at
- Owner: writetome51
- License: mit
- Created: 2018-11-06T22:57:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-11-14T00:08:07.000Z (about 4 years ago)
- Last Synced: 2025-02-15T02:06:51.055Z (11 months ago)
- Topics: array-manipulations, insert, items, javascript, new, typescript
- Language: JavaScript
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# insertAt\(
index,
values: T[],
array: T[]
): void
At `index`, `values` are inserted in `array`.
`index` can be negative or positive. If positive, existing items beginning at that index
will be pushed to the right to make room. If negative, existing items ending at that
index will be pushed to the left to make room. No items get removed.
## Examples
```js
let arr = [1,2,3,4];
insertAt(2, [7, 8], arr);
// arr is now [1,2,7,8,3,4]
let arr = [1,2,3,4];
insertAt(-1, [7, 8], arr);
// arr is now [1,2,3,4,7,8]
let arr = [1,2,3,4];
insertAt(-4, [7, 8], arr);
// arr is now [1,7,8,2,3,4]
```
## Installation
`npm i @writetome51/array-insert-at`
## Loading
```js
import { insertAt } from '@writetome51/array-insert-at';
```