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

131
Views
¿Cómo filtro un valor de clave en un objeto en función del valor coincidente?

Tengo un objeto que contiene objetos. ¿Cómo filtro el valor de "título" en función de si la identificación coincide?

 { "0": { "id": 1912, "title": "Fiction", }, "1": { "id": 1957, "title": "Non-Fiction", }, "2": { "id": 1958, "title": "Literature", }, }

Por ejemplo, si const id= 1958 , entonces la salida: Literatura

Producción:

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

0

Puedes probar esto:

 let data = { "0": { "id": 1912, "title": "Fiction", }, "1": { "id": 1957, "title": "Non-Fiction", }, "2": { "id": 1958, "title": "Literature", }, }; let getTitle = (obj, id)=>{ return Object.values(obj).filter(x=>x.id===id)?.[0]?.title }; console.log(getTitle(data,1958))

También puede usar find en lugar de filter .

Sin encadenamiento opcional según el comentario de OP:

 let data = { "0": { "id": 1912, "title": "Fiction", }, "1": { "id": 1957, "title": "Non-Fiction", }, "2": { "id": 1958, "title": "Literature", }, }; let getTitle = (obj, id)=>{ let element = Object.values(obj).find(x=>x.id===id); return element ? element.title : ""; }; console.log(getTitle(data,1958))

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!