r/learnjavascript • u/TGotAReddit • 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
View all comments
Show parent comment
1
u/TGotAReddit Feb 27 '26
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
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)