2 ms·
You can also use `.map()` and `Object.fromEntries` if you really don’t want to mutate the accumulator: function keyByUsername(person) { return [perso
by runarberg 7y ago
You can also use `.map()` and `Object.fromEntries` if you really don’t want to mutate the accumulator:
function keyByUsername(person) {
return [person.username, person];
}
const peopleObj = Object.fromEntries(peopleArr.map(keyByUsername));
But you should probably be using a `Map` for this anyway:
const peopleMap = new Map(peopleArr.map(keyByUsername));