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

170
Views
Mapping over an array - Return of map is undefined

I'm still quite new to JS and don't understand why this function returns undefined. What am I not seeing?

const people = [
{ name: 'Ben', year: 1980 },
{ name: 'John', year: 1985 },
{ name: 'Bob', year: 1971 }
];

and my function:

const myFunction = () => {
people.map((person) => {
    return person.year;
});
};

console.log(myFunction());

Thanks y'all

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

0

const people = [{
    name: 'Ben',
    year: 1980
  },
  {
    name: 'John',
    year: 1985
  },
  {
    name: 'Bob',
    year: 1971
  }
];
const myFunction = () => {
  const newPeople = people.map((person) => {
    return person.year;
  });
  return newPeople;
};

console.log(myFunction());

you need to return the value you want it to be returned

now the output is as below:

[1980, 1985, 1971]
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!