score:1

Accepted answer
const moviesNamesAndGenres = [
   {id: 28, name: "Action"},
   {id: 12, name: "Adventure"},
   {id: 14, name: "Animation"}
]

const genreIds = [14, 28, 13];


const test = genreIds.map((genreId) => {
      const matchedGenres = moviesNamesAndGenres.find((movieObj) => {
         return movieObj.id === genreId
      })
      return matchedGenres // this returns the matching objects, cool
})
const result = test.filter(Boolean).map((el) => {
  return el.name
})

console.log(result)

score:0

const moviesNamesAndGenres = [   {id: 28, name: "Action"},   {id: 12, name: "Adventure"},   {id: 14, name: "Animation"}],
      genreIds = [14, 28, 13],
      result = genreIds.map(g => (moviesNamesAndGenres.find(m => m.id === g) || {}).name).filter(Boolean);
        
console.log(result);

Related Query

More Query from same tag