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 trialPeter Retvari
Full Stack JavaScript Techdegree Student 8,392 Pointssolution 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);
2 Answers
Daniel Santos
34,969 PointsGood job!
Sail Liao
6,654 Pointsconst favoriteBooks = users.reduce((acc, user) => { user.favoriteBooks.forEach(book => acc.push(book.title)) return acc; }, [])
It's also possible with just forEach in reduce.
Alexander Davison
65,469 PointsAlexander Davison
65,469 Points