Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialZach Freitag
20,341 Pointsmap method on the authors array, create an array of full name strings, comprising the first name, space, last name.
Using the map method on the authors array, create an array of full name strings, comprising the first name, then a space, then the last name. See the comments below for reference. Store the new array in the fullAuthorNames variable.
const authors = [
{ firstName: "Beatrix", lastName: "Potter" },
{ firstName: "Ann", lastName: "Martin" },
{ firstName: "Beverly", lastName: "Cleary" },
{ firstName: "Roald", lastName: "Dahl" },
{ firstName: "Lewis", lastName: "Carroll" }
];
let fullAuthorNames;
// fullAuthorNames should be: ["Beatrix Potter", "Ann Martin", "Beverly Cleary", "Roald Dahl", "Lewis Carroll"]
// Write your code below
2 Answers
Zach Freitag
20,341 PointsThis worked!
fullAuthorNames = authors
.map(authors => `${authors.firstName} ${authors.lastName}`);
console.log(fullAuthorNames);
Nnanna Okoli
Front End Web Development Techdegree Graduate 19,181 PointsfullAuthorNames = authors.map(author => ${author.firstName} ${author.lastName}
);
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsAakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsThanks Zach Freitag
David Shulkin
Front End Web Development Techdegree Student 10,255 PointsDavid Shulkin
Front End Web Development Techdegree Student 10,255 PointsWhats happening in this code is that were mapping over the authors array, which is creating a new array (fullAuthorNames - the template literals are concatenating both property values in each object as an array value and storing them in the new array (fullAuthorNames).
You could also write it in arrow function syntax like so:
fullAuthorNames = authors.map( author => { return `${author.firstName} ${author.lastName}` } )