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

162
Visualizações
Get parent object, by nested property

I have the following object, an array with databases, each containing a collection of tables, each containing a collection of columns.

Console Output

I want to obtain the parent table, given the Id of a column and tried to avoid iterating over the collection. Just a very simple clean single line.

I was initially trying but quickly was challenged by the fact Tables is not an array but a collection which doesn't support .some statements.

let table = schema.find((database,index) => database.Tables.some((column,index) => column.Id === 1234));

Is there a smart way or conversion trick that I have overlooked that prevents me from having to iterate the entire structure?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use Object.values() to get an array of columns from your Tables object:

let table = schema.find(database => Object.values(database.Tables).some(column => column.Id === 1234));

Alternately, you could use Object.keys() and write it like this:

let table = schema.find(database => Object.keys(database.Tables)
                                          .some(columnName => database.Tables[columnName].Id === 1234));
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