xxxxxxxxxx
const users = [
{ name: 'John', age: 30, designation: 'Developer' },
{ name: 'Wilson', age: 26, designation: 'Designer' },
{ name: 'Riya', age: 45, designation: 'Business analyst' },
{ name: 'John', age: 30, designation: 'Developer' },
{ name: 'Sandeep', age: 22, designation: 'Tech Lead' },
];
//duplicate_emp = { 30: 1, 26:1, 45:1, 22:1 }
const output = users.reduce((acc, curr) => {
if(acc[curr.age]){
acc[curr.age] = ++acc[curr.age];
}else{
acc[curr.age] = 1;
}
return acc;
}, {});
console.log(output);