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

114
Views
¿Cómo lanzar objetos?

tengo este objeto:

 { "id": "Test", "firstname": "Test", "lastname": "Test", "age": 83 }

pero quiero devolver el objeto solo con este valor:

 { "id": "Test" }

¿Cómo convertir el primer objeto a otro usando TS/NodeJS?

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

0

Podría escribir una función como esta que use un descriptor de acceso de property accessor para devolver solo la id del objeto:

 let data = { id: 'Test', firstname: 'Test', lastname: 'Test', age: 83, }; function trimToId(data) { return { id: data.id }; } console.log(trimToId(data))

Si quisiera hacer esto más conciso, podría usar una arrow function con destructuring :

 let data = { id: 'Test', firstname: 'Test', lastname: 'Test', age: 83 }; const trimToId = ({ id }) => ({ id }); console.log(trimToId(data));

about 4 years ago · Juan Pablo Isaza Report

0

Creo que lo que está buscando es un Tipo de utilidad llamado Parcial. Puede encontrar la documentaciónaquí .

 interface FirstObject { id: string; firstname: string; lastname: string; age: number; } const firstObject: FirstObject = { "id": "Test", "firstname": "Test", "lastname": "Test", "age": 83 }; const secondObject: Partial<FirstObject> = { "id": "Test" };

about 4 years ago · Juan Pablo Isaza Report

0

function foo(input) { return {id: input.id}; }
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!