I have this code:
const arraySalesperson = ["John", "Alice", "Bob", "John", "John", "Alice"];
const arraySales = [100, 420, 138, 89, 74, 86];
const arrayGoals = [1, 2, 3, 4, 5, 6];
// create a map
const resultsBySalesperson = new Map();
// traverse the list of salespersons
for (let i = 0; i < arraySalesperson.length; i++) {
const name = arraySalesperson[i];
// see if it already exists in the map
let salesperson = resultsBySalesperson.get(name);
if (!salesperson) {
// if not, let's create an object now
salesperson = {
name: name,
sales: 0,
goals: 0
};
// store it in the map
resultsBySalesperson.set(name, salesperson);
}
// update the object
salesperson.sales += arraySales[i];
salesperson.goals += arrayGoals[i];
}
// here you have the map ready with both sales and goal properly accumulated
console.info([...resultsBySalesperson.entries()]);
I need to use the properties salesperson.sales and salesperson.goals. How can I pick those properties? Ive tried to use:
resultsBySalesperson.get(name)
resultsBySalesperson.get(salesperson.sales)
resultsBySalesperson.get(salesperson.goals)
But I think I'm doing something wrong