remove(42) vs. find(42).remove()
- 592 words
- 3 minutes to read
- comments
We have a list of books in the books
object. How do we remove a single book from it, given that we know its ID? We can do books.removeById(42)
. Alternatively, we can find it with books.findById(42)
and then call b.remove()
. Which option should we prefer, and why? The second choice is the better one. Not only because it’s more object-oriented, but also due to several practical advantages.