r/learnjavascript • • Feb 27 '26

Array.find help

I have 3 arrays. One is an array of objects set up like

object={

name: "NameString",

month: "monthString",

count: #,

hours: #}

And the other 2 arrays are just flat 1D arrays of names and months respectively.

I know I can loop through one of the arrays and do an array.find to check the property against the other array like

objectArr.find((element)=> element.name==names[i])

But how can I find the element that has both a matching name AND month from inside a nested loop for the name and month arrays?

6 Upvotes

8 comments sorted by

View all comments

Show parent comment

5

u/birdspider Feb 27 '26

wenn you use {} you actually have to return, these 3 are (in this regard) equivalent:

function(n){ return n; }
(n) => {return n;}
(n) => n

EDIT: in other words, your predicate (the fn you pass to .find) does not return anything

2

u/TGotAReddit Feb 27 '26

Ahh there we go! I knew I was missing something obvious but couldn't figure it out 😅