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 in Arrays

Peter Retvari
Peter Retvari
Full Stack JavaScript Techdegree Student 8,392 Points

Maybe it's not a proper way, but it's shorter and you got the same result

HI guys,

Maybe it's not a proper way, but it's shorter and you got the same result:

const users = [
  {name: 'Samir', age: 32},
  {name: 'Angela', age: 25},
  {name: 'Beatrice', age:56}

const reducedUsers = {};

users.reduce((acc, curr)=> reducedUsers[curr.name] = curr.age ,0);


I created an object, which will hold the value (acc). Each iteration I give this object a new key value pair with the current name and age value.

2 Answers

Jordan Kittle
.a{fill-rule:evenodd;}techdegree seal-36
Jordan Kittle
Full Stack JavaScript Techdegree Graduate 20,147 Points

This is the first workshop where I wasn't able to come up with the solution to the challenge on my own. I think expecting us to figure out we need to pass an empty object as the initializer and return the object each iteration is a bit too much considering we never learned about that in the lesson.

Dane Parchment
Dane Parchment
Treehouse Moderator 11,074 Points

You are correct that this is a way to do this with less code. However, I recommend that you follow along with the concepts covered in the video. It is better that you learn all the different ways to do something instead of just one way. Especially since the .reduce() method you are using will be covered in a later video.