Skip to content

Instantly share code, notes, and snippets.

@masautt
Created September 6, 2019 18:55
Show Gist options
  • Save masautt/7c7766dc75bfd420df4d53c58133b866 to your computer and use it in GitHub Desktop.
Save masautt/7c7766dc75bfd420df4d53c58133b866 to your computer and use it in GitHub Desktop.
How to remove all even numbers from an array in JavaScript?
function removeEvens(arr){
return arr.filter(function (num) {
return num % 2 !== 0;
});
}
console.log(removeEvens([8,6,7,5,3,0,9])); // --> [ 7, 5, 3, 9 ]
// https://stackoverflow.com/questions/18305431/how-to-remove-all-odd-numbers-in-an-array-using-javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment