An open API service indexing awesome lists of open source software.

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

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;
```