if I have a js array like below, is there a simple way to re-group the array values by age? I tried to reduce it to an array but it did not help. it’s re-grouped with age or name’s
let employees = [
{
firstName:"Zion",
lastName: "Rosy",
age: 25,
joinedDate:"January 24, 2020",
},
{
firstName: "Ana",
lastName: "Rosy",
age: 25,
joinedDate: "January 15, 2019",
},
{
firstName: "Zion",
lastName:"Albert",
age: 30,
joinedDate:"February 15, 2011",
},
];
To re-group by age like this:
let organizedByAge =
{
25: [
{
firstName:"Zion",
lastName: "Rosy",
age: 25,
joinedDate:"January 24, 2020",
},
{
firstName: "Ana",
lastName: "Rosy",
age: 25,
joinedDate: "January 15, 2019",
},
],
30: [
{
firstName:"Zion",
lastName:"Albert",
age: 30,
joinedDate:"February 15, 2011",
},
],
};