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

105
Views
Find element in map

I have a map of objects:

"0": {
    key: 'id',
    value: {
        name: "eval"
        // other variables
    }
},
"1": {
    key: 'id',
    value: {
        name: "help"
        // other variables
    }
} // and so on

I need to find an element in map that's name variable is eqaul to "eval". What's the easiest way to do this?

about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

If "map" is an array

let arr = [{key:'id', value:{ name:'eval' }}]
let item = arr.find(el => el.value.name == 'eval')

If "map" is an object

let obj = {0:{key:'id', value:{ name:'eval' }}}
let item = Object.values(obj).find(el => el.value.name == 'eval')
about 4 years ago · Santiago Gelvez Report

0

Use <Array>.from to convert map values to array and after filter what you want.

const map = new Map();

map.set(0, {
  key: 'id',
    value: {
      name: "eval"
    }
});

map.set(1, {
  key: 'id',
    value: {
      name: "help"
    }
});

const result = Array.from(map.values())
  .filter(x => x.value.name === 'eval')[0];
  
console.log(result);

about 4 years ago · Santiago Gelvez Report

0

simple and best solution

const tmp = {
  "0": {
    key: "id",
    value: {
      name: "eval"
      // other variables
    }
  },
  "1": {
    key: "id",
    value: {
      name: "eval"
      // other variables
    }
  }
};

function findEval(obj, target) {
    for (var i=0; i < Object.keys(obj).length; i++) {
        if (obj[i].value.name === target) {
            return obj[i].value.name;
        }
    }
}
console.log(findEval(tmp, 'eval'))
about 4 years ago · Santiago Gelvez 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!