https://github.com/writetome51/array-replace-at
Replaces 1 item in array at specified index
https://github.com/writetome51/array-replace-at
array-manipulations item javascript replace typescript
Last synced: 2 months ago
JSON representation
Replaces 1 item in array at specified index
- Host: GitHub
- URL: https://github.com/writetome51/array-replace-at
- Owner: writetome51
- License: mit
- Created: 2018-11-09T08:58:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-03T07:03:25.000Z (over 7 years ago)
- Last Synced: 2025-07-05T19:22:31.610Z (about 1 year ago)
- Topics: array-manipulations, item, javascript, replace, typescript
- Language: TypeScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# replaceAt(index, newValue, array): void
Replaces item at `index` with `newValue` in `array`.
`index` can be negative or positive.
## Examples
```
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
replaceAt(1, 20, arr);
// arr is now [ 1, 20, 3, 4, 5, 6, 7, 8, 9, 10 ]
replaceAt(-1, 20, arr);
// arr is now [ 1, 20, 3, 4, 5, 6, 7, 8, 9, 20 ]
replaceAt(0, 'hello', arr);
// arr is now [ 'hello', 20, 3, 4, 5, 6, 7, 8, 9, 20 ]
replaceAt(-2, [21, 22], arr);
// arr is now [ 'hello', 20, 3, 4, 5, 6, 7, 8, [21, 22], 20 ]
```
## Installation
`npm i @writetome51/array-replace-at`
## Loading
```
import {replaceAt} from '@writetome51/array-replace-at';
var replaceAt = require('@writetome51/array-replace-at').replaceAt;
```