Logo

Programming-Idioms

History of Idiom 135 > diff from v38 to v39

Edit summary for version 39 by programming-idioms.org:
Admin deletes impl 2889: This doesn't properly handle x not found and indexOd returning -1

Version 38

2020-09-30, 09:08:31

Version 39

2020-09-30, 09:10:42

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Idiom #135 Remove item from list, by its value

Remove at most 1 item from list items, having value x.
This will alter the original list or return a new list, depending on which is more idiomatic. If there are several occurrences of x in items, remove only one of them.

Variables
items,x
Variables
items,x
Code
const index = items.indexOf(x);
items.splice(index, 1);