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 Nested Data and Additional Exploration

Peter Retvari
seal-mask
.a{fill-rule:evenodd;}techdegree
Peter Retvari
Full Stack JavaScript Techdegree Student 8,392 Points

solution with forEach ?

Dears,

I solved this challenge in another way too. If you're interested, let's check it out here ?:

const arr = [];  
const bookTitles = users.forEach( user => {
  user.favoriteBooks.forEach(title=> { 
      arr.push(title.title);
  });
});
console.log(arr);

:+1:

2 Answers

Good job!

Sail Liao
Sail Liao
6,654 Points

const favoriteBooks = users.reduce((acc, user) => { user.favoriteBooks.forEach(book => acc.push(book.title)) return acc; }, [])

It's also possible with just forEach in reduce.