Skip to content

Instantly share code, notes, and snippets.

@masautt
Created September 3, 2019 23:26
Show Gist options
  • Save masautt/76be367edee65ac1b5a87853fcef724e to your computer and use it in GitHub Desktop.
Save masautt/76be367edee65ac1b5a87853fcef724e to your computer and use it in GitHub Desktop.
How to remove an element from an array in JavaScript?
let arr = [1, 2, 3, 4, 5];
// Remove from the front
arr.pop();
console.log(arr); // --> [2, 3, 4, 5];
// Remove from back
arr.unshift( );
console.log(arr); // --> [2, 3, 4]
// Remove based on a condition
// Condition is if even
arr.filter((elem) => {
return (elem %2 !== 0)
})
console.log(arr); // --> [3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment