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

177
Visualizações
Reading value of variable in javascript find

I try to read the value of the key color_ids in the following JavaScript associative array:

  const UrlArray = [
    {
      bd_shoe_size_ids: ["6601", "6598"]
    },
    {
      color_ids: ["6056", "6044"]
    },
    {
      manufacturer_ids: ["5875", "5866"]
    }
  ]

This was done by the following code:

UrlArray.find(({color_ids}) => color_ids); 

But I would like to use this code for reading the value of other array keys to. For that I want to store the name of the array key whose value I want to know in a variable. If I use the code below it will of course look for a key called nameOfArrayKey, but is it possible to search for the value of the variable: nameOfArrayKey?

UrlArray.find(({nameOfArrayKey}) => nameOfArrayKey);
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

I had the same problem. Try this:

console.log(UrlArray.map(Object.keys).flat())
about 4 years ago · Juan Pablo Isaza Relatório

0

you can use hasOwnProperty property to check object has key name

function getObject(urlArray,nameKey){
  const object= urlArray.find(value=>{
     return value.hasOwnProperty(nameKey)
  });
  return object;
}

about 4 years ago · Juan Pablo Isaza Relatório

0

So, basically, you can try something like this :

const k = "manufacturer_ids"
console.log(UrlArray.find((o) => o[k]))

Output :

{ manufacturer_ids: [ '5875', '5866' ] }
about 4 years ago · Juan Pablo Isaza 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