Logo

Programming-Idioms

History of Idiom 135 > diff from v17 to v18

Edit summary for version 18 by me:
New JS implementation by user [me]

Version 17

2018-09-22, 15:17:45

Version 18

2019-09-26, 16:23:13

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.

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