Skip to content

Instantly share code, notes, and snippets.

@masautt
Created September 6, 2019 18:53
Show Gist options
  • Save masautt/9f149ed3ec221795efd0d6ae97854568 to your computer and use it in GitHub Desktop.
Save masautt/9f149ed3ec221795efd0d6ae97854568 to your computer and use it in GitHub Desktop.
How to remove all odd numbers from an array in JavaScript?
function removeOdds(arr){
return arr.filter(function (num) {
return num % 2 === 0;
});
}
console.log(removeOdds([8,6,7,5,3,0,9])); // --> [ 8, 6, 0 ]
// 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