Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

91
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda