@writetome51/array-get-and-remove-all-before
v1.1.3
Published
2 functions: one removes and returns all array items before the first instance of a particular value, and the other removes and returns all array items before the last instance of a particular value
Downloads
7
Maintainers
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;