Skip to content

Instantly share code, notes, and snippets.

@bobdobbalina
Last active August 2, 2021 15:34
Show Gist options
  • Save bobdobbalina/165c5f276046efff75bf1d8a049f7140 to your computer and use it in GitHub Desktop.
Save bobdobbalina/165c5f276046efff75bf1d8a049f7140 to your computer and use it in GitHub Desktop.
Javascript: Remove items from array
// 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