Logo

Programming-Idioms

History of Idiom 135 > diff from v23 to v24

Edit summary for version 24 by joewrong:
[JS] whoops

Version 23

2019-09-26, 16:56:17

Version 24

2019-09-26, 16:56:40

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
const index = items.find(li => li === x);
items.splice(index, 1);
Code
const index = items.indexOf(x);
items.splice(index, 1);