+ 1
Reduce get a object in an array with reduce
How do you get a object out of a array with reduce? So if the element that contains the object object is a property name with value "rendang," then pick up the entire object and store it on the mysel variable. So how can I do that with reduce? https://code.sololearn.com/Wo39IUiAqqkw/?ref=app
4 Réponses
+ 1
Mirielle👽 I was thinking that, too, but I was just trying to see if the reduce could do that, too
+ 1
with reduce ?
reduce((p, n)=> (!p && n.name == "Rendang")? n: p, null)
imo filter is the best way, the intent are much clearer by using filter instead of reduce.
0
try this:
var mysel = myData.filter(obj => obj.name == "Rendang")
console.log(mysel)
0
Thank you so much everyone!! It was solved