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

147
Views
Filtrar json por clave en Javascript

Necesito filtrar un json que obtengo externamente de la API. El archivo json es así:

 { "get":"players", "parameters":{ "team":"504", "season":"2021" }, "response":[ { "player":{ "id":1011, "name":"K. R\u00fcegg", "firstname":"Kevin", "lastname":"R\u00fcegg", [...] }, { "player":{ "id":14268, "name":"I. Pandur", "firstname":"Ivor", "lastname":"Pandur", "age":21, "birth":{ [...]

Sintaxis:

 fetch(url) .then(response => response.json()) .then((data) => { [...] });

Necesito obtener solo la identificación del jugador seleccionado de esta manera:

 "player":{ "id":1011, "name":"K. R\u00fcegg", "firstname":"Kevin", "lastname":"R\u00fcegg", [...] },
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Espero que el siguiente código de ejemplo le dé una idea.

Usé JsonPlaceholder Mock API https://jsonplaceholder.typicode.

La salida de datos de la API mencionada anteriormente es:

 [ { "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false }, { "userId": 1, "id": 2, "title": "quis ut nam facilis et officia qui", "completed": false }, { "userId": 1, "id": 3, "title": "fugiat veniam minus", "completed": false }, [...]

Tengo que separar el siguiente resultado seleccionado de la API mencionada anteriormente (su ID es 187):

 { completed: false, id: 187, title: "consequuntur animi possimus", userId: 10 }

Para eso he usado el siguiente código JS:

 var targetID = 187; // need to filter with following ID fetch('https://jsonplaceholder.typicode.com/todos/') .then(response => response.json()) .then((data) => { const result = data.filter(function (el) { return el.id == targetID; // Changed the matching value }); console.log('FIltered Value', result); });

Violín de trabajo https://jsfiddle.net/katheer_mizal/9jdh5wuy/1/

Más detalles:

Js analiza y filtra un json

Encuentra objeto por id en una matriz de objetos de JavaScript

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!