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 trial

JavaScript JavaScript Array Iteration Methods Combining Array Methods Working with Objects

map 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.

app.js
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

This worked!

fullAuthorNames = authors
  .map(authors => `${authors.firstName} ${authors.lastName}`);
console.log(fullAuthorNames);
David Shulkin
seal-mask
.a{fill-rule:evenodd;}techdegree
David Shulkin
Front End Web Development Techdegree Student 10,255 Points

Whats 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}` } )