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

107
Visualizações
Filter a json with array of values - JavaScript

I want to filter a json array that looks like the below code:

const data = 
  [ { __typename  : 'GEP_validate_response_graph_type'
    , status      : 'APROVADO_COM_ACOES'
    , informative : [ 'Manifestação obrigatória sem documento.'] 
    , pendencias  : 
      [ { __typename : 'GEP_validate_action_graph_type'
        , action     : 'MANIFESTACAO_OBRIGATORIA_SEM_DOCUMENTO'
        , optional   : false
        , message    : 'Manifestação obrigatória sem documento.'
        , id         : null
      } ] 
    , tarefa_id   : 'e4cdb007-a223-5547-a49f-c47c06fd2c52'
    } 
  , { __typename  : 'GEP_validate_response_graph_type'
    , status      : 'APROVADO_COM_ACOES'
    , informative : [ 'Manifestação obrigatória sem documento.'] 
    , pendencias  : 
      [ { __typename : 'GEP_validate_action_graph_type'
        , action     : 'MANIFESTACAO_OBRIGATORIA_SEM_DOCUMENTO'
        , optional   : true
        , message    : 'Manifestação obrigatória sem documento.'
        , id         : null
      } ] 
    , tarefa_id   : '361e4c79-9605-fd4f-b7bd-47a3916ad070'
  } ] 

I want to return only the optional == true, and after that I will get the lenght of this object.

I tryed this, but did not work:

const pedido_filter = acoes_filter.pendencias.filter(
    (pendencia) =>
      pendencia.optional == true
  );

How do I do that?

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

0

You can use Array.some for testing if the pendencias array contains atleast one optional key with value as true

let x = [{
    "__typename": "GEP_validate_response_graph_type",
    "status": "APROVADO_COM_ACOES",
    "informative": [
      "Manifestação obrigatória sem documento."
    ],
    "pendencias": [{
      "__typename": "GEP_validate_action_graph_type",
      "action": "MANIFESTACAO_OBRIGATORIA_SEM_DOCUMENTO",
      "optional": false,
      "message": "Manifestação obrigatória sem documento.",
      "id": null
    }],
    "tarefa_id": "e4cdb007-a223-5547-a49f-c47c06fd2c52"
  },
  {
    "__typename": "GEP_validate_response_graph_type",
    "status": "APROVADO_COM_ACOES",
    "informative": [
      "Manifestação obrigatória sem documento."
    ],
    "pendencias": [{
      "__typename": "GEP_validate_action_graph_type",
      "action": "MANIFESTACAO_OBRIGATORIA_SEM_DOCUMENTO",
      "optional": true,
      "message": "Manifestação obrigatória sem documento.",
      "id": null
    }],
    "tarefa_id": "361e4c79-9605-fd4f-b7bd-47a3916ad070"
  }
];


x = x.filter((item) => item.pendencias.some(y => y.optional));
console.log(x);

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