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

109
Views
Problema al obtener una matriz dentro de una matriz

Tengo un problema con un objeto dentro de una matriz y quería mostrar solo eso como una matriz.

datos1

 const data1 = [ { "id": "01", "info": "fefef", "sub": "hieei", "details": { "data": "fruits" } }, { "id": "02", "info": "fefef", "sub": "hieei", "details": { "data": "things" } } ]

Rendimiento esperado

 const final= [ { "data": "fruits" }, { "data": "things" } ]

Código

 const final = data.map((data) => { ...data})
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Mapee a través de la matriz y extraiga su propiedad de details :

 const data1 = [ { "id": "01", "info": "fefef", "sub": "hieei", "details": { "data": "fruits" } }, { "id": "02", "info": "fefef", "sub": "hieei", "details": { "data": "things" } } ] const res = data1.map(e => e.details) console.log(res)

about 4 years ago · Juan Pablo Isaza Report

0

map sobre la matriz y devuelva un nuevo objeto usando la propiedad de detalles. Si no devuelve un nuevo objeto, su nueva matriz aún tendrá referencias a los objetos en la matriz original. Entonces, si cambia el valor de una propiedad en esa matriz original, ese cambio también se reflejará en la nueva matriz, y probablemente no quiera que eso suceda.

 const data1=[{id:"01",info:"fefef",sub:"hieei",details:{data:"fruits"}},{id:"02",info:"fefef",sub:"hieei",details:{data:"things"}}]; // Make sure you return a copy of the // details object otherwise if you change the details // of the original objects in the array // the new mapped array will carry those object changes // because the array objects will simply references to the old objects const out = data1.map(obj => { return { ...obj.details }; }); console.log(out);

about 4 years ago · Juan Pablo Isaza Report

0

El uso del map y la desestructuración simplificarán.

 const data1 = [ { id: "01", info: "fefef", sub: "hieei", details: { data: "fruits", }, }, { id: "02", info: "fefef", sub: "hieei", details: { data: "things", }, }, ]; const res = data1.map(({ details: { data } }) => ({ data })); console.log(res); // if you just need the details object const res2 = data1.map(({ details }) => details); console.log(res2);

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!