Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

67
Vistas
How to get value in single array extracted from nested array only through map function

How to get value in single array not in nested array without any additional operation outside map function.

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)

Orignal Output : [ [ '10', '20' ], [ '30', '40' ] ]
Expected Output : [10,20,30,40]

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

This should work well The age array needs to be declared outside

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 Denunciar

0

as I understand your code in your age array you are exactly getting the desired result. instead of printing and assigning agelist you can just use the map methods as below

const List = []

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

)

List.map((list, index) => {

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

}) console.log(age)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try this way :

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda