Logo

Programming-Idioms

History of Idiom 135 > diff from v37 to v38

Edit summary for version 38 by programming-idioms.org:
Admin deletes impl 2865: This would remove all occurrences, instead of just 1

Version 37

2020-05-03, 21:28:16

Version 38

2020-09-30, 09:08:31

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
items = items.filter(i => i !== val);
Comments bubble
This returns a new list without the item
Doc URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter