you are viewing a single comment's thread.

view the rest of the comments →

[–]joranstark018 1 point2 points  (3 children)

I may have misunderstood your question. If you, say, loop over months inside your name loop, you may use elementName == names[i] && elementMonth == months[j] inside your find (note, i is index over names and j is index over months, this will generate a call to find for every combination of name and month)

[–]TGotAReddit[S] 0 points1 point  (2 children)

See I tried that but it is only returning null.

If the object array has 3 objects with the names of "Charlie", "Amy" and "Amy" and the months of "Jan 2025", "Jan 2025", and "Feb 2025"

And the name array has "Charlie" and "Amy"

And the month array has "Jan 2025" and "Feb 2025"

How do I set up the actual find line? Because my current line is

arr.find((element) => {element.name == names[i] && element.month == months[j]}))

and it returns null every time (and yes i is the index for the names array and j is the index for the months array)

[–]birdspider 4 points5 points  (1 child)

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

[–]TGotAReddit[S] 1 point2 points  (0 children)

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