Skip to content

2 functions that remove all items that come after a certain value in the array

License

Notifications You must be signed in to change notification settings

writetome51/array-remove-all-after

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

removeAllAfterFirst(value, array): void

Removes everything after first instance of value in array.

removeAllAfterLast(value, array): void

Removes everything after last instance of value in array.

For both, value cannot be an object. It can be an array.

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]  

Installation

npm i @writetome51/array-remove-all-after

Loading

// if using TypeScript:
import {removeAllAfterFirst, removeAllAfterLast} from '@writetome51/array-remove-all-after';
// if using ES5 JavaScript:
var removeAllAfterFirst = 
    require('@writetome51/array-remove-all-after').removeAllAfterFirst;
var removeAllAfterLast = 
    require('@writetome51/array-remove-all-after').removeAllAfterLast;

About

2 functions that remove all items that come after a certain value in the array

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published