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

82
Views
Nodejs anula o agrega otra respuesta de retorno

Tengo una variable, FirstName y LastName, quiero agregarla a la respuesta de retorno,

tenga en cuenta que FirstName y LastName no están presentes/disponibles en la tabla Student.

 let result = await Student.get(id) let FirstName = "Paul" let LastName = "Richard" results = { ...result, FirstName: params.body.FirstName, LastName: params.body.LastName }

resultado actual

 { 0:{ "Teacher": "adasfsafag", "Subject": "asdafdfhd", }, "FirstName": "Paul", "LastName": "Richard" }

lo que quiero es

 { "Teacher": "adasfsafag", "Subject": "asdafdfhd", "FirstName": "Paul", "LastName": "Richard" }

cuando no agregué el nombre y el apellido en la respuesta

este es el resultado

 { "data": { "School":{ "Teacher": "adasfsafag", "Subject": "asdafdfhd" } } }
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Debe distribuir el nodo anidado School esta manera:

 const result = { "data": { "School":{ "Teacher": "adasfsafag", "Subject": "asdafdfhd", } } }; const FirstName = "Paul"; const LastName = "Richard"; results = { ...result.data.School, FirstName, LastName }; console.log(results);
 .as-console-wrapper { max-height: 100% !important; top: 0 }

about 4 years ago · Santiago Trujillo Report

0

Desestructurar el primer elemento de la matriz. Es posible que desee comprobar algunos límites antes de hacer esto...

 if (result.length) { results = { ...result[0], FirstName: params.body.FirstName, LastName: params.body.LastName } // or results2 = { Teacher:result[0].Teacher, Subject:result[0].Subject, FirstName: params.body.FirstName, LastName: params.body.LastName } }
about 4 years ago · Santiago Trujillo 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!