https://github.com/writetome51/array-get-and-remove-all-before
2 functions: one removes and returns all array items before the first instance of a value, and the other removes and returns all array items before the last instance of a value
https://github.com/writetome51/array-get-and-remove-all-before
array-manipulation get-item javascript remove typescript
Last synced: 11 months ago
JSON representation
2 functions: one removes and returns all array items before the first instance of a value, and the other removes and returns all array items before the last instance of a value
- Host: GitHub
- URL: https://github.com/writetome51/array-get-and-remove-all-before
- Owner: writetome51
- License: mit
- Created: 2018-11-06T07:01:31.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-01T00:52:27.000Z (almost 7 years ago)
- Last Synced: 2024-09-22T09:02:25.824Z (over 1 year ago)
- Topics: array-manipulation, get-item, javascript, remove, typescript
- Language: TypeScript
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# getAndRemoveAllBeforeFirst(
value,
array
): any[]
Removes and returns everything before the first instance of `value` in `array`.
# getAndRemoveAllBeforeLast(
value,
array
): any[]
Removes and returns everything before the last instance of `value` in `array`.
## Examples:
```
let arr = [3,4,5,6,7,8,9,6,7];
let removed = getAndRemoveAllBeforeFirst(6, arr);
// removed is now [3,4,5].
// arr is now [6,7,8,9,6,7].
let arr = [1,2,3,4,5,1,6,7,8,9];
let removed = getAndRemoveAllBeforeLast(1, arr);
// removed is now [1,2,3,4,5].
// arr is now [1,6,7,8,9].
```
## Installation
`npm i @writetome51/array-get-and-remove-all-before`
## Loading
```
// if using TypeScript:
import {getAndRemoveAllBeforeFirst, getAndRemoveAllBeforeLast}
from '@writetome51/array-get-and-remove-all-before';
// if using ES5 JavaScript:
var getAndRemoveAllBeforeFirst =
require('@writetome51/array-get-and-remove-all-before').getAndRemoveAllBeforeFirst ;
var getAndRemoveAllBeforeLast =
require('@writetome51/array-get-and-remove-all-before').getAndRemoveAllBeforeLast;
```