I'm studying the map function and tried to make a contrived example which I thought would work. This code works fine:
let students = [{name: 'Susan', grades: [88, 38, 28]}, {name: 'Robert', grades: [28,97, 17]}];
let newStudents = students.map((el) => el.name);
console.log(newStudents); // [ 'Susan', 'Robert' ]
But what I really wanted was the following in the map function:
let newStudents = students.map((el) => {name: el.name});
// [ undefined, undefined ]
// I assumed to get back the following: [ {name: 'Susan'}, {name: 'Robert'} ]
Why is using an object in the return portion of the map function not allowed?
let newStudents = students.map((el) => {return {name: el.name}});