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

90
Views
FIlter an Object based on a key and get the value for that key

Let's say I have an input and typed hosu so what I want to be able to do is filter through this objects and get the value for it.So I should get 321234 which is the pincode for hosurRoad. How do i achieve this?

const recoganizedAreas = {
  'hsr':'560102',
  'bypanahalli':'676667',
  'marathalli':'667776',
  'hosurRoad':'321236',
  'teachersColony':'560101'
};

const areas = Object.keys(recoganizedAreas);


about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Maybe you can use recoganizedAreas[ areas[3] ] to get value for hosurRoad of recoganizedAreas

Also you can reach of 3 for hosurRoad of areas by using areas.indexOf("hosurRoad")

console.log(recoganizedAreas[ areas[3] ])
"321236"
about 4 years ago · Santiago Trujillo Report

0

You can just get the key and access the value from Object directly.

const text = 'hosu';
const recoganizedAreas = {
  'hsr':'560102',
  'bypanahalli':'676667',
  'marathalli':'667776',
  'hosurRoad':'321236',
  'teachersColony':'560101'
};

const key = Object.keys(recoganizedAreas).find(key => key.includes(text));
if(recoganizedAreas[key]) {
    console.log(recoganizedAreas[key])
}

about 4 years ago · Santiago Trujillo Report

0

I don't quite understand the request because if you have an object you can just access the property you are looking for.

If you have to do some business logic based on key value you can use Object.entries to filter the object by key

here some example

const recoganizedAreas = {
  'hsr':'560102',
  'bypanahalli':'676667',
  'marathalli':'667776',
  'hosurRoad':'321236',
  'teachersColony':'560101'
};

const areas = Object.keys(recoganizedAreas)

const hosurPinCode = recoganizedAreas.hosurRoad

console.log(hosurPinCode)

const objectFilteredByKey = (key) => Object.fromEntries(
Object.entries(recoganizedAreas).filter(([k, _]) => k === key)
)
   
console.log(objectFilteredByKey('hosurRoad'))  

about 4 years ago · Santiago Trujillo 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!