Y
Flattening an array is nothing but returning only selected items in the form of array . we can push only the needed value instead of the item . see the example below const utubers=[{id:1,name:'Test Ed',sal:5000},{id:2,name:'Dev Ed',sal:5000},{id:3,name:'Mr Beast',sal:2000},{id:4,name:'Mr Boss',sal:2000},{id:5,name:'MKBHD',sal:5000}] const salGt2000ids = utubers.reduce(((tempArray,utuber)=>{ // get an array with only whose sal is more than 2000 if(utuber.sal>2000){ tempArray.push(utuber.id) } return tempArray; } ),[]) console.log(salGt2000ids); //[1, 2, 5]
