I have an Array of Objects like this
const obj = [
{
id: 1,
name: "Abc"
},
{
id: 2,
name: "BED"
},
{
id: 1,
name: "FGH"
},
{
id: 3,
name: "RFS"
},
{
id: 1,
name: "Abc"
},
{
id: 2,
name: "BGH"
}
]
I want to club the objects who have same id and same name so that my Final output looks like this-
const result = [
[
{
id: 1,
name: "Abc"
},
{
id: 1,
name: "Abc"
}
],
[
{
id: 1,
name: "TSD"
}
],
[
{
id: 2,
name: "BED"
}
],
[
{
id: 2,
name: "BGH"
}
],
[
{
id: 3,
name: "RFS"
}
]
]
Note - I have about 300-400 objects in the array and I have used nested For loops to solve this problem. Therefore I am looking for a better and fast solution