I don’t know what’s happening here, more specifically, I was able to follow everything until now, but since prototypes etc it has been a real struggle and I have no idea if I can actually wrap my head around this concepts and more than anything else apply them to the creation of a webpage, since so far it has been a ton of theory with zero practise on the real thing.
Anyway, now, I’m not even doing the exercise, I don’t uderstand the example. This is an arrow function, right?
Ok, where does obj come from? reduce is called on users (users.reduce), how do we know obj refers to users? In the lesson it was written that the callback function of reduce accepts 4 arguments, and that for this example only two were going to be used, the first being the accumulator (so the result of the last return of the callback function) and the second which is the current element being processed…well, it doesn’t look like that in the function to me, how’s obj and user the elements being processed in that order? And ultimately, where does the final , {}); come from?
I’m starting to think that I’m really dumb because this doesn’t make any sense to me…if anyonw could dumb down this for me maybe I’ll be able to understand what’s going on
const users = [
{ name: 'John', age: 34 },
{ name: 'Amy', age: 20 },
{ name: 'camperCat', age: 10 }
];
const usersObj = users.reduce((obj, user) => {
obj[user.name] = user.age;
return obj;
}, {});
console.log(usersObj);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36
Challenge: Use the reduce Method to Analyze Data
Link to the challenge: