-1

How can I use filtering an array of objects

Roy Fied
  • 29
  • 2

2 Answers2

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