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

128
Visualizações
best way to find object

I need to find object by property children_inherit where value is true and return this object. what is the best way to do this, maybe it possible to do this with lodash library or better with clean js?

please check object below...

{ 

    "file": [ 

        { 

            "children_inherit": false, 

             "value": "123123"

        }, 

        { 

            "children_inherit": false, 

            "value": "asdad" 

        } 

    ], 

    "sample": [ 

        { 

            "children_inherit": true, 

            "value": "1231" 

        } 

    ], 

    "treatment": [ 

        { 

            "children_inherit": false, 

            "value": "asdasd"

        } 

    ] 

} 

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

0

Object.values is returning the values of the object (i.e: "file" value, "sample" value etc..). In the first for loop, you access those values and then in the second for loop, you can access the each object inside the arrays and voila:

const obj = { 
    "file": [ 
        { 
            "children_inherit": false, 
             'value': 123123 
        }, 
        { 
            "children_inherit": false, 
             'value': 'asdad' 
        } 
    ], 
    "sample": [ 
        { 
            "children_inherit": true, 
             'value': '1231' 
        } 
    ], 
    "treatment": [ 
        { 
            "children_inherit": false, 
             "value": 'yoyoyo' 
        } 
    ] 
}

let value

for(const v of Object.values(obj)) {  
    for(let k of v) {
      if(k.children_inherit) value = k.value
    } 
}

console.log(value)
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