I'm on the path to creating a new object where names are grouped together based on matching IDs. The solution isn't perfect yet, but progress is being made.
const names = [
{id:1,name:"jame"},
{id:2,name:"jill"},
{id:3,name:"hanna"},
{id:3,name:"clark"}
]
const newNames = []
// Working towards this goal
names.foreach((person,index) => {
if(newNames[index].id === person.id){
newNames.push({id:person.index, names:[...newNames.name,person.name]})
}else{
newNames.push({id:person.index, person.name})
}
})
The desired result would resemble this:
const newNames = [
{id:1,name:"jame"},
{id:2,name:"jill"},
{id:3,names: {name:"clark",name:"hanna"}}
]
Encountered Issue: Cannot read properties of undefined (reading 'id')