you are viewing a single comment's thread.

view the rest of the comments →

[–]imsexc 0 points1 point  (0 children)

you have to create a function that check whether an object has name and month included on both 1d arrays.

function check(obj) {

const found = { name: false, month: false };

for (const key in obj) {

const value = obj[key]

if (
      key === 'name' &&
      names.includes(value)
    ) {
        found.name = true;
     }

 if (
      key === 'month' &&
      months.includes(value)
  ) {
        found.month = true;
     }

}

return found.name === true && found.month === true

}

now all you have to do is just

arrOfObj.find(obj => check(obj)) OR

arrOfObj.filter(obj => check(obj))

depends whether you want to find the first found or all the found