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

207
Views
¿Cómo agregar una nueva matriz de objetos a un objeto para anidarlo y si ya existe una matriz recién agregada, agregar otro objeto a esa matriz?

Tengo una serie de objetos question.json que se parece a

 "id": "2", "ques": "here is my second code ?", "quesBrief": "I can't seem to find it too.", "hashes": "#javascript , #goodlord", "author": "slowdeathv123", "dateTime": "2021-09-22 18:13:12", "date": "2021-09-22", "sortOrder": -99, "code": " - utlis (folder contains GO files)\n ---sendMail.go \n--templates (folder)\n --- reset_code.html\n - main.go"

Quiero agregarle una matriz de respuestas de objetos para convertirlo en un objeto anidado y agregar más objetos a la matriz de respuestas usando una solicitud de espera fetch/axios/async para que sea como

 "id": "2", "ques": "here is my second code ?", "quesBrief": "I can't seem to find it too.", "hashes": "#javascript , #goodlord", "author": "slowdeathv123", "dateTime": "2021-09-22 18:13:12", "date": "2021-09-22", "sortOrder": -99, "code": " - utlis (folder contains GO files)\n ---sendMail.go \n--templates (folder)\n --- reset_code.html\n - main.go" "answers": [ { "answerBrief": "Check under the bed", "answerCode": "no code sorry", "answerAuthor": "Sonya" }, { "answerBrief": "Any other random solution", "answerCode": "no code sorry", "answerAuthor": "ABC" } ],

¿Cómo crear una solicitud de publicación para agregar una matriz de objetos dentro de un objeto mientras verifica si la matriz de respuestas ya existe, si no crea una y agrega objetos?

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

0

¿Esto tiene sentido?

 let data = { "id": "2", "ques": "here is my second code ?", "quesBrief": "I can't seem to find it too.", "hashes": "#javascript , #goodlord", "author": "slowdeathv123", "dateTime": "2021-09-22 18:13:12", "date": "2021-09-22", "sortOrder": -99, "code": " - utlis (folder contains GO files)\n ---sendMail.go \n--templates (folder)\n --- reset_code.html\n - main.go", }; const newAnswer = { "answerBrief": "Check under the bed", "answerCode": "no code sorry", "answerAuthor": "Sonya" }; const answers = [...data.answers || [], newAnswer]; data = { ...data, answers }

Si necesita agregar respuestas que vienen después de la solicitud POST:

 fetch('your-api-url-to-add-answers', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) // data with answers i think? }) .then(res => res.json()) .then(answersData => { const answers = [...data.answers || [], answeersData]; data = { ...data, answers } });

Si necesitas enviar datos con respuestas actualizadas:

 const answers = [...data.answers || [], answeersData]; const payload = { ...data, answers } fetch('your-api-url-to-add-answers', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) // data with answers i think? }) .then(res => res.json()) .then(answersData => {});

Pero para una respuesta más precisa, proporcione un poco más de detalle. Qué datos deben enviarse en una solicitud posterior y qué tipo de respuesta recibe del servidor.

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!