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