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

66
Views
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 answers
Answer question

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 Report

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 Report

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 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!