You can do this mapping with a "one-liner":
const returnValue = employees.reduce((p,v) => (p[v.acctName] = [...(p[v.acctName] || []), `${v.firstName} ${v.lastName}`], p), {})
Where:
`${v.firstName} ${v.lastName}` is used to construct firstName + ' ' + lastName via a Template Literal
(p[v.acctName] || []) is used to use the existing array, or a new one if the there is none, using the Shortcut Or operator
[...x, y] uses the spread operator ... to copy the array x (from the previous explanation above) and add a new element y to that new array
(x, y), the comma operator, is used to evaluate x and then return y; we evaluate p[v.acctName] [...(p[v.acctName] || []), `${v.firstName} ${v.lastName}`], then return p, which is required for Array.prototype.reduce to work properly
(p,v) => (...) is an arrow function; we use parentheses to tell JavaScript that the contents are a return value, not a function block, and also to make sure that the comma operator isn't interpreted as a separate parameter for Array.prototype.reduce rather than part of the Arrow function
Array.prototype.reduce is used to collapse many values into one; here, we use it to collapse the list using the function (p,v) => (p[v.acctName] = [...(p[v.acctName] || []), `${v.firstName} ${v.lastName}`], p) into the value {} (a new Object)
This answer is more of a "here's some really cool things you can do in JavaScript", and while some developers might prefer this style, the other answers are probably better in performance and legibility. You can reformat this code to read:
const returnObject = employees.reduce(
(p, v) => (
(p[v.acctName] = [ // Assign array to p[v.acctName]
...(p[v.acctName] || []), // copy old array or make a new array
`${v.firstName} ${v.lastName}`, // template literal
]),
p // returns p for next Array.prototype.reduce call
),
{} // Object to be populated by acctName: [...names]
);
Edit:
After playing with performance a bit, I came up with:
const returnValue = employees.reduce((p, { acctName, firstName, lastName }) => {
const name = firstName + " " + lastName, values = p.get(acctName) || [];
values.push(name);
values.length == 1 && p.set(acctName, values);
return p;
}, new Map());
Which now ranks 11% faster than the Nagendra's solution, and 24% better than Phil's, while still being relatively concise. I'd like to take a moment to thank both of them for teaching me some stuff about performance today.
This answer is more of a "there are many ways to do the same thing in JS" anyways, just another set of alternatives to work with.