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
cómo puedo obtener datos de una matriz anidada y obtener el resultado
const source = [ { id: "1", data: { first_name: "Rian", last_name: "Nugraha" }, school: { id: "1", data: "PLMK-JKT" }, }, { id: "2", full_name: "Ari Santoso", school: { id: "1", short_name: "GRSR", data: "JKT" }, }, { id: "3", data: { first_name: "Rahman", last_name: "Sunggara" }, school: { id: "1", short_name: "GELM", data: "JKT" }, }, { id: "4", data: { first_name: "Rian", last_name: "Nugraha" }, school: { id: "2", data: "PLMK-BDG" }, }, ]

entonces, quiero combinar first_name y last_name en el nombre completo de la matriz anidada o combinar short_name y datos en la matriz anidada de la escuela pero siempre sin definir, el resultado es el siguiente:

{ nombre : 'Rian Nugraha', nombre_escuela: 'PLMK-JKT }

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

0

Aquí cómo acceder a la matriz @ elemento (0) y combinar nombres y apellidos

 var fullName = source[0].data.first_name + " " + source[0].data.last_name;

Para agregar la escuela:

 var fullNameAndSchool = source[0].data.first_name + " " + source[0].data.last_name + " is from school " + source[0].school.data;
about 4 years ago · Juan Pablo Isaza Report

0

Hizo usando un operador ternario

 const source = [ { id: "1", data: { first_name: "Rian", last_name: "Nugraha" }, school: { id: "1", data: "PLMK-JKT" }, }, { id: "2", full_name: "Ari Santoso", school: { id: "1", short_name: "GRSR", data: "JKT" }, }, { id: "3", data: { first_name: "Rahman", last_name: "Sunggara" }, school: { id: "1", short_name: "GELM", data: "JKT" }, }, { id: "4", data: { first_name: "Rian", last_name: "Nugraha" }, school: { id: "2", data: "PLMK-BDG" }, }, ] const resArray = source.map((el) => { let name = el.data? (el.data.first_name+" "+el.data.last_name): el.full_name; let school_name = el.school.short_name? (el.school.short_name+" "+el.school.data): el.school.data; const result = { name: name, school_name: school_name } return result; }) console.log(resArray)

about 4 years ago · Juan Pablo Isaza Report

0

const result = source.map(({data, school, full_name}) => { return {name: (typeof data) === "undefined" ? full_name : `${data.first_name + " "+ data.last_name}`, school_name: school.hasOwnProperty("short_name") ? `${school.short_name + " "+ school.data}` : school.data}; }); console.log(result); /*[ { name: 'Rian Nugraha', school_name: 'PLMK-JKT' }, { name: 'Ari Santoso', school_name: 'GRSR JKT' }, { name: 'Rahman Sunggara', school_name: 'GELM JKT' }, { name: 'Rian Nugraha', school_name: 'PLMK-BDG' } ]*/
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!