Last active
August 2, 2021 15:34
-
-
Save bobdobbalina/165c5f276046efff75bf1d8a049f7140 to your computer and use it in GitHub Desktop.
Javascript: Remove items from array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you know multiple values | |
const items = ['a', 'b', 'c', 'd', 'e', 'f']; | |
const valuesToRemove = [ 'c', 'd' ]; | |
const filteredItems = items.filter(( item ) => !valuesToRemove.includes( item )); | |
// ["a", "b", "e", "f"] | |
// If you know the value | |
const items = ['a', 'b', 'c', 'd', 'e', 'f'] | |
const valueToRemove = 'c' | |
const filteredItems = items.filter(item => item !== valueToRemove) | |
// ["a", "b", "d", "e", "f"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment