Created
September 3, 2019 23:26
-
-
Save masautt/76be367edee65ac1b5a87853fcef724e to your computer and use it in GitHub Desktop.
How to remove an element from an array in JavaScript?
This file contains hidden or 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
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