1.0.4 • Published 5 years ago
@writetome51/array-remove-all-after-before v1.0.4
To include:
import {removeAllAfterFirst, removeAllAfterLast, removeAllBeforeFirst, removeAllBeforeLast}
from '@writetome51/array-remove-all-after-before';
This package has 4 functions. They all return void.
For all of them, the parameter 'value' cannot be an object.
removeAllAfterFirst(value, array); // removes everything in array after first instance of value.
removeAllAfterLast(value, array); // removes everything after last instance of value.
removeAllBeforeFirst(value, array); // removes everything before first instance of value.
removeAllBeforeLast(value, array); // removes everything before last instance of value.
Examples:
let arr = [5,10,15,20,10,50,60,70];
removeAllAfterFirst(10, arr);
// arr is now [5,10]
let arr = [5,10,15,20,10,50,60,70];
removeAllAfterLast(10, arr);
// arr is now [5,10,15,20,10]
let arr = [5,10,15,[20,22],10,50,[20,22],60];
removeAllBeforeFirst([20,22], arr);
// arr is now [[20,22],10,50,[20,22],60]
let arr = [5,10,15,[20,22],10,50,[20,22],60];
removeAllBeforeLast([20,22], arr);
// arr is now [[20,22],60]