How can I use filtering an array of objects
Asked
Active
Viewed 56 times
-1
-
[2,6,7,34,78,31,89,64].filter(x => x % 2 !== 0) – kevinSpaceyIsKeyserSöze Mar 29 '21 at 12:01
2 Answers
2
Use array.filter()
The below should work no problem
const oddNums = (array) => {
const results = array.filter(num => num % 2 !== 0)
return results
}

Dan Wilstrop
- 355
- 1
- 4
- 12
0
You can try using for loop,
let a = [2,6,7,34,78,31,89,64];
let b = [];
for(var i=0;i<=a.length-1;i++){
if(a[i] % 2!==0){
b.push(a[i]);
}
}
console.log(b);

RGA
- 303
- 3
- 11