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

73
Views
Cómo obtener valor en una matriz única extraída de una matriz anidada solo a través de la función de mapa

Cómo obtener valor en una matriz única, no en una matriz anidada sin ninguna operación adicional fuera de la función de mapa.

 const List = [] List.push( { name: 'John', id: 383, Value: [ { "Age": "10" }, { "Age": "20" } ], }, { name: 'Mark', id: 545, Value: [ { "Age": "30" }, { "Age": "40" } ], } ) const ageList = List.map((list, index) => { let age = []; list.Value.map(item => { age.push(item.Age) }) return age }) console.log(ageList)

Salida original: [ [ '10', '20' ], [ '30', '40' ] ]
Salida esperada: [10,20,30,40]

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

0

Esto debería funcionar bien La matriz de edad debe declararse fuera

 var age=[] const ageList = List.map((list, index) => { list.Value.map(item => { age.push(item.Age) }) return; }) console.log(age)
about 4 years ago · Juan Pablo Isaza Report

0

según entiendo su código en su matriz de edad, está obteniendo exactamente el resultado deseado. en lugar de imprimir y asignar una lista de edad, puede usar los métodos de mapa como se muestra a continuación

const Lista = []

 List.push( { name: 'John', id: 383, Value: [ { "Age": "10" }, { "Age": "20" } ], }, { name: 'Mark', id: 545, Value: [ { "Age": "30" }, { "Age": "40" } ], }

)

List.map((lista, índice) => {

 let age = []; list.Value.map(item => { age.push(item.Age) })

}) consola.log(edad)

about 4 years ago · Juan Pablo Isaza Report

0

Prueba de esta manera:

 const List = [{ name: 'John', id: 383, Value: [ { "Age": "10" }, { "Age": "20" }] },{ name: 'Mark', id: 545, Value: [ { "Age": "30" }, { "Age": "40" } ], }]; const age = []; List.forEach((list, index) => { list.Value.forEach(item => { age.push(item.Age); }) }); console.log(age);

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!