How to extract only the odd numbers from an array in JavaScript

1 Answer

0 votes
const arr  = [1,2,3,4,5,6,7,8,9,10];

const oddNumbers = arr.filter((e, i) => e % 2 === 1);

console.log(oddNumbers);



/*
run:

[1, 3, 5, 7, 9] 

*/

 



answered May 19, 2021 by avibootz

Related questions

...