map
function calls getNames
function for each item of the array.
Each time the function getNames
returns only names from each objectlet myFavoritePlanets = [
{name: 'Earth', radius: 6371},
{name: 'Jupiter', radius: 69911},
{name: 'Neptune', radius: 24622, moons: ['Triton', 'Thalassa', 'Nereid', 'Proteus', 'Hippocamp', 'Naiad']}
]
let namesOnly = myFavoritePlanets.map(getNames);
function getNames(planet) {
return planet.name
}
console.log(namesOnly);