Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
return the value of the matching items in an array

I have two arrays that I would like to compare and return a respective value of the ones that match.

Taking the 'id' variable as a reference, I want to return all the matching values of fastFood, but only the 'name'.

My expected result is to return Five Guys and KFC, but instead, it returns the entire object.

let id = ['1234'];
let fastFood = [
  {_id:'4391', name: "McDonalds"}, 
  {_id:'7654', name: "Burger King"}, 
  {_id:'8765', name: "Dominos"}, 
  {_id:'1234', name: "Five Guys"}, 
  {_id:'9876', name: "Subway"}, 
  {_id:'1234', name: "KFC"}
];


const findFastFood = ids.filter((item) => {
  if (item._id.indexOf(id) !== -1) {
    return item.name;
  }
});

console.log(findFastFood);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Does this help?

let id = ['1234'];
let fastFood = [{
    _id: '4391',
    name: "McDonalds"
  },
  {
    _id: '7654',
    name: "Burger King"
  },
  {
    _id: '8765',
    name: "Dominos"
  },
  {
    _id: '1234',
    name: "Five Guys"
  },
  {
    _id: '9876',
    name: "Subway"
  },
  {
    _id: '1234',
    name: "KFC"
  }
];


const findFastFood = fastFood.filter((item) => {
  if (id.indexOf(item._id) !== -1) {
    return item.name
  }

}).map(obj => obj.name);


console.log(findFastFood);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!