Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Filtrar un json con una matriz de valores - JavaScript

Quiero filtrar una matriz json que se parece al siguiente código:

 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' } ]

Quiero devolver solo el == true opcional , y luego obtendré la longitud de este objeto.

Intenté esto, pero no funcionó:

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

¿Cómo puedo hacer eso?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar Array.some para probar si la matriz de pendencias contiene al menos una clave optional con valor como 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!